[php-src] Issue #24792: PHP 8.6: Assignment-result writes compile but fail with invalid opcode
| From: | alwyn1024 | Date: | Tue, 27 Oct 2026 15:36:36 +0000 |
| Subject: | [php-src] Issue #24792: PHP 8.6: Assignment-result writes compile but fail with invalid opcode | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-253243@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/24792
Author: alwyn1024
### Description
## Summary
In PHP 8.6.0RC4, writing to an array dimension on an assignment result compiles successfully, but
execution fails with an
Invalid opcode fatal error.
PHP 8.5.10 rejects the same construct during compilation.
## Minimal reproducer
```php
<?php
($a = [1])[0] = 2;
var_dump($a);
```
### Actual behavior
**PHP 8.5.10:** Compilation fails:
```
Fatal error: Cannot use temporary expression in write context
```
**PHP 8.6.0RC4:** php -l succeeds, but executing the code fails:
```
Fatal error: Invalid opcode 23/2/1.
```
### Reference-assignment control
```php
<?php
$b = [1];
($a =& $b)[0] = 2;
var_dump($a, $b);
```
PHP 8.6.0RC4 accepts and executes this successfully, with both arrays containing [2].
Other assignment-derived property writes, destructuring-result writes, compound assignments,
unset, and reference-binding operations exhibit related discrepancies.
## Expected behavior / clarification requested
Should assignment-derived dimension and property writes be rejected during compilation, or should
PHP generate valid writable operands for these expressions?
In particular, is the ordinary-assignment failure a compiler emission defect, a missing compile-time
rejection, or an intentional distinction between ordinary and reference-assignment results?
## Affected versions
- PHP 8.5.10 — Windows x64
- PHP 8.6.0RC4 — Windows x64, NTS, VC2022
- PHP 8.6 source commit: f23b4c222cebe33be93ee8ecaaa14390c5507a08
The PHP 8.6 executable was built from the specified source commit.
Reproduction: php -n -l example.php, followed by php -n example.php.
## Relevant implementation
-
[[zend_compile_var_inner](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_compile.c#L12774)](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_compile.c#L12774)
- [[ZEND_ASSIGN_DIM
handlers](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_vm_def.h#L2680)](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_vm_def.h#L2680)
- [[Related PR
#20628](https://github.com/php/php-src/pull/20628)](https://github.com/php/php-src/pull/20628)
The compiler appears to allow assignment ASTs in writable contexts while producing operand kinds
unsupported by the corresponding VM write handlers.
I would appreciate clarification of the intended behavior before treating these forms as valid or
invalid PHP source syntax.
### PHP Version
```plain
PHP 8.6.0RC4 (cli) (built: Oct 25 2026 12:45:36) (NTS Visual C++ 2022 x64)
Copyright © The PHP Group and Contributors
Zend Engine v4.6.0RC4, Copyright © Zend by Perforce
with Zend OPcache v8.6.0RC4, Copyright ©, by Zend by Perforce
```
### Operating System
Windows x64 (64-bit), PHP 8.6.0RC4 NTS, Visual C++ 2022 (VC17)