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

parse $result = &($context->getPageData()); not ok,have any idea ? #996

Closed
dengyl2018 opened this issue May 8, 2024 · 2 comments
Closed

Comments

@dengyl2018
Copy link

parse $result = &($context->getPageData()); not ok,error:

Fatal error: Uncaught PhpParser\Error: Syntax error, unexpected ';', expecting '[' or T_OBJECT_OPERATOR or T_NULLSAFE_OBJECT_OPERATOR or '{' on line 36 in /PhpParser/ParserAbstract.php:318
Stack trace:
#0 /PhpParser/ParserAbstract.php(159): PhpParser\ParserAbstract->doParse()
#1 /PhpParser/Parser/Multiple.php(51): PhpParser\ParserAbstract->parse('<?php\n/...', Object(PhpParser\ErrorHandler\Throwing))
#2 PhpParser/Parser/Multiple.php(32): PhpParser\Parser\Multiple->tryParse(Object(PhpParser\Parser\Php7), Object(PhpParser\ErrorHandler\Throwing), '<?php\n/
...')
#3 php_parser.php(23): PhpParser\Parser\Multiple->parse('< in /PhpParser/ParserAbstract.php on line 318

for compare, parse $a = $context->getPageData(); $result = &$a; is ok

@dryabov
Copy link

dryabov commented May 8, 2024

Simply because it is not valid PHP code. Try to run it in PHP and you get almost the same parsing error syntax error, unexpected token ";", expecting "->" or "?->" or "{" or "[": https://3v4l.org/vpiSi

@nikic
Copy link
Owner

nikic commented May 9, 2024

That's right -- the right hand side of & needs to be a "variable" (in a very specific sense that cannot be briefly explained) and (...) is not a variable.

@nikic nikic closed this as completed May 9, 2024
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

3 participants