From 0a80b2d8eee0b51d3826ed228e0c794add0c2f45 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 19 Oct 2019 10:49:07 +0200 Subject: [PATCH] Fix PHP 8 compatibility This is a fix to preserve current behavior, but this should be changed towards doing the same as PHP 8 does. --- lib/PhpParser/Lexer.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/PhpParser/Lexer.php b/lib/PhpParser/Lexer.php index 07ec5ca..012c1f9 100644 --- a/lib/PhpParser/Lexer.php +++ b/lib/PhpParser/Lexer.php @@ -143,6 +143,16 @@ class Lexer return true; } + if (PHP_VERSION_ID >= 80000) { + // PHP 8 converts the "bad character" case into a parse error, rather than treating + // it as a lexing warning. To preserve previous behavior, we need to assume that an + // error occurred. + // TODO: We should handle this the same way as PHP 8: Only generate T_BAD_CHARACTER + // token here (for older PHP versions) and leave generationg of the actual parse error + // to the parser. This will also save the full token scan on PHP 8 here. + return true; + } + return null !== error_get_last(); }