Hi internals,
I opened PR #20903 <https://github.com/php/php-src/pull/20903> to address
GH-10497 <https://github.com/php/php-src/issues/10497> by allowing writes
to properties of objects referenced by consts (const binding stays
immutable, referenced objects can be mutable).
class C { public int $x = 0; } const OBJ = new C(); OBJ->x = 1;
// currently rejected, PR makes it valid var_dump(OBJ->x); // 1
Notes:
-
This is a language/semantics change and may overlap with / impact
GH-13800 <https://github.com/php/php-src/pull/13800>.
-
A potentially surprising case: some newly-valid writes can be a no-op
when they target a temporary const value, e.g.
- const X = [1,2,3]; X[] = 4;
- const Y = ['a' => 1]; Y['b'] = 2;
These become valid syntax but have no effect because the write happens on a
temporary basis.
Feedback on semantics + expected behavior for the temporary-write case is
appreciated.
Thanks,
__
*Khaled Alam*