[php-src] PR #20903: Fix GH-10497: Allow const obj->prop = value
| From: | khaledalam | Date: | Sun, 11 Jan 2026 02:17:24 +0000 |
| Subject: | [php-src] PR #20903: Fix GH-10497: Allow const obj->prop = value | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-34510@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/20903
Author: khaledalam
## Description
Fixes #10497 - Allows direct modification of object properties stored in constants.
## Problem
Previously, this code would fail with a fatal error:
```php
const a = new stdClass;
a->b = 42; // Fatal error: Cannot use temporary expression in write context
```
### 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:
- Added Zend/tests/gh10497.phpt - comprehensive test for the fix
- **Updated** Zend/tests/gh12102_3.phpt - reflects improved constant handling
### Behavior
Now supports all property operations on constant objects:
```php
const obj = new stdClass;
obj->prop = 'value';
obj->prop = 'new value';
obj->another = 'test';
obj->counter = 0;
obj->counter++;
obj->num = 10;
obj->num += 5;
unset(obj->prop);
obj->nested = new stdClass;
obj->nested->value = 123;
```
The constant reference remains immutable, but the object itself is mutable as expected.