Skip to content

Fix list() assignment in array literals #11322

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

Merged
merged 2 commits into from
May 26, 2023
Merged

Conversation

iluuu1994
Copy link
Member

Fixes GH-11320

This is a bit messy :( The LHS of assignment can look like other expressions, but is interpreted differently in the compiler. This makes evaluating the LHS unsafe. I'm not aware of other such AST elements but I wouldn't rule it out. It might be better to revert the original commit... The idea was to simplify, not make it more complicated.

@nielsdos
Copy link
Member

It looks correct and seems to work.
But tbh, I liked the original code better because it is more straightforward. As you said it's easy to overlook other edge cases. I get why you wanted to generalise of course, maybe you can go back to the original code and add descriptive asserts or something like that?
If you would end up reverting, then please keep the tests you added, because apparently the code paths were untested before.

iluuu1994 added 2 commits May 26, 2023 10:43
Array literals will constant evaluate their elements. These can include
assignments, even though these are not valid constant expressions. The lhs of
assignments can be a list() element (or []) which is parsed as an array with a
special flag.
@iluuu1994
Copy link
Member Author

@nielsdos Done. Thanks for your insight 🙂

@iluuu1994 iluuu1994 merged commit fbe6696 into php:master May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP Fatal error: Cannot use list() as standalone expression
2 participants