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

Fatal error when trying to recover from specific code snippet #362

Closed
Gert-dev opened this issue Mar 5, 2017 · 3 comments
Closed

Fatal error when trying to recover from specific code snippet #362

Gert-dev opened this issue Mar 5, 2017 · 3 comments

Comments

@Gert-dev
Copy link

Gert-dev commented Mar 5, 2017

Hello

I'm receiving a multitude of warnings and a fatal error from the PHP parser when trying to parse the following (erroneous) code with php-parse Test.php -r -P (i.e. with error recovery enabled):

<?php

function foo()
{
    return $this->arrangements->filter(function (LodgingArrangement $arrangement) {
        return   
    })->first(); 
}

The following output is generated:

PHP Notice:  Undefined offset: 27 in /home/user/core/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 318
PHP Notice:  Undefined offset: 27 in /home/user/core/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 274
PHP Fatal error:  Uncaught Error: Unsupported operand types in /home/user/core/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php:1395
Stack trace:
#0 /home/user/core/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php(262): PhpParser\Parser\Php7->reduceRule145()
#1 /home/user/core/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php(50): PhpParser\ParserAbstract->parse('<?php\n\nfunction...', Object(PhpParser\ErrorHandler\Collecting))
#2 /home/user/core/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php(31): PhpParser\Parser\Multiple->tryParse(Object(PhpParser\Parser\Php7), Object(PhpParser\ErrorHandler\Collecting), '<?php\n\nfunction...')
#3 /home/user/core/vendor/nikic/php-parser/bin/php-parse(61): PhpParser\Parser\Multiple->parse('<?php\n\nfunction...', Object(PhpParser\ErrorHandler\Collecting))
#4 {main}
  thrown in /home/user/core/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php on line 1395

Expected output: some sort of error node or nothing at all if error recovery fails, but not a fatal PHP error and warnings.

This is happening with php-parser 3.0.4 on PHP 7.1.2.

Thanks in advance

@nikic
Copy link
Owner

nikic commented Mar 5, 2017

I can confirm that this issue exists on v3.0.4. However, it is not present on HEAD of 3.x. Presumably this was fixed as part a side-effect of #359.

@nikic
Copy link
Owner

nikic commented Mar 5, 2017

I've published a new release for 3.x, which includes the referenced patches: https://github.com/nikic/PHP-Parser/releases/tag/v3.0.5

@nikic nikic closed this as completed Mar 5, 2017
@Gert-dev
Copy link
Author

Gert-dev commented Mar 5, 2017

Doh, I've literally just released a new version of my package with the specific Git commit and came here to report that it is indeed fixed. No problem though, now I'll be able to lock Composer to a specific version again instead of a commit. Keep up the great work! 👍

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

2 participants