Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] Parser crashes on an empty file #967

Closed
ondrejmirtes opened this issue Dec 20, 2023 · 1 comment
Closed

[5.0] Parser crashes on an empty file #967

ondrejmirtes opened this issue Dec 20, 2023 · 1 comment

Comments

@ondrejmirtes
Copy link
Contributor

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
@nikic nikic closed this as completed in f7d484a Dec 20, 2023
@ondrejmirtes
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant