Fix GH-10497: Allow const obj->prop = value#20903
Fix GH-10497: Allow const obj->prop = value#20903khaledalam wants to merge 3 commits intophp:masterfrom
Conversation
iluuu1994
left a comment
There was a problem hiding this comment.
Thanks @khaledalam! Looks reasonable overall.
Thanks @iluuu1994 for the feedback, all comments addressed. |
|
Cool, thanks @khaledalam! This is a language change and should be discussed on the internals mailing list at least. I think this will impact GH-13800, but that's not a major issue. |
|
Btw, one thing in particular people might object to is: const arrayTest = [1, 2, 3];
arrayTest[] = 4;
var_dump(arrayTest);This becomes valid, but prints: I.e. the assignment has no effect, because it happens on a temporary value. Make sure to mention this in your e-mail to internals. |
|
I've opened an internals thread and sent an email for discussion: https://news-web.php.net/php.internals/129757 |
|
It sounds like @TimWolla objected, so this would need an RFC, or at least the mitigation from https://news-web.php.net/php.internals/129839. |
TimWolla
left a comment
There was a problem hiding this comment.
Yes, my replies on the list were an objection against the PR as-is. Selecting request changes for visibility.
|
Noted, I'll look into it |
Pass type parameter to zend_compile_const() instead of bool use_tmp Check BP_VAR_R/BP_VAR_IS for read mode Remove unnecessary wrapper function Return void instead of zend_op*
d488d10 to
b0a2437
Compare
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.