-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix GH-10497: Allow const obj->prop = value #20903
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
Fix GH-10497: Allow const obj->prop = value #20903
Conversation
@iluuu1994
iluuu1994
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @khaledalam! Looks reasonable overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should pass type directly and only produce IS_VAR when in write-context (BP_VAR_W or BP_VAR_RW).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_compile_const() is only used from one other place, no need for this BC layer. You can just pass BP_VAR_R from zend_compile_expr_inner().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return value should be unneded. It's only needed for specific opcodes, e.g. to add some extended_value flag. Just return NULL from zend_compile_var_inner().
Description
Fixes #10497 - Allows direct modification of object properties stored in constants.
Problem
Previously, this code would fail with a fatal error:
Solution
Modified the compiler to properly handle ZEND_AST_CONST in variable compilation contexts:
Constants now emit IS_VAR instead of IS_TMP_VAR when used in write contexts
This allows property assignment opcodes to work correctly with constant objects
Tests:
Behavior
Now supports all property operations on constant objects:
The constant reference remains immutable, but the object itself is mutable as expected.