nikic / PHP-Parser

A PHP parser written in PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[5.0] Parser crashes on an empty file

ondrejmirtes opened this issue · comments

When you give an empty file to bin/php-parse, it crashes the parser:

====> File empty.php:
PHP Warning:  Attempt to read property "id" on array in /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 249

Warning: Attempt to read property "id" on array in /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 249
PHP Warning:  Attempt to read property "text" on array in /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 253

Warning: Attempt to read property "text" on array in /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 253
PHP Fatal error:  Uncaught RangeException: The lexer returned an invalid token (id=0, value=) in /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:255
Stack trace:
#0 /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php(183): PhpParser\ParserAbstract->doParse()
#1 /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/bin/php-parse(68): PhpParser\ParserAbstract->parse('')
#2 /Users/ondrej/Development/BetterReflection/vendor/bin/php-parse(119): include('/Users/ondrej/D...')
#3 {main}
  thrown in /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 255

Fatal error: Uncaught RangeException: The lexer returned an invalid token (id=0, value=) in /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:255
Stack trace:
#0 /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php(183): PhpParser\ParserAbstract->doParse()
#1 /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/bin/php-parse(68): PhpParser\ParserAbstract->parse('')
#2 /Users/ondrej/Development/BetterReflection/vendor/bin/php-parse(119): include('/Users/ondrej/D...')
#3 {main}
  thrown in /Users/ondrej/Development/BetterReflection/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 255

Thank you very much! As you can tell, I'm in process of testing 5.0 :) I've rewritten and tested:

And now I'm in the process of rewriting https://github.com/phpstan/phpstan-src which is most time-consuming. I'll let you know in #929 once I'm done and if there are any more issues.