[php-src] Issue #20396: bug in all 8.x versions
| From: | Slavo-S | Date: | Wed, 05 Nov 2025 12:09:29 +0000 |
| Subject: | [php-src] Issue #20396: bug in all 8.x versions | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251179@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/20396
Author: Slavo-S
### Description
The following code:
```<?php
$arrA = array('a' => array('x' => 100), 'b' =>
array('x' => 200), 'c' => array('x' => 300)); // Array of
Arrays
$arrO = json_decode('[{"id": 1, "val": 10}, {"id": 2,
"val": 20}, {"id": 3, "val": 30}]'); // Array of Objects
foreach ($arrA as &$val) $val['x'] += 2; // this doesnt work (variable $val)
//foreach ($arrA as &$val2) $val2['x'] += 2; // this works (renamed reference
variable)
foreach ($arrO as $val) {
foreach ($arrA as $item) error_log($item['x']); // last item in $arrA changed from
Array to Object in array $arrO !!!
break; // other itteration resulted in same error (last item changed)
}
```
Resulted in this output:
[05-Nov-2025 12:55:36 Europe/Bratislava] 102
[05-Nov-2025 12:55:36 Europe/Bratislava] 202
[05-Nov-2025 12:55:36 Europe/Bratislava] PHP Fatal error: Uncaught Error: Cannot use object of type
stdClass as array in
But I expected this output instead:
[05-Nov-2025 12:54:32 Europe/Bratislava] 102
[05-Nov-2025 12:54:32 Europe/Bratislava] 202
[05-Nov-2025 12:54:32 Europe/Bratislava] 302
### PHP Version
```plain
PHP 8.4.7 (cli) (built: May 6 2025 14:14:22) (NTS Visual C++ 2022 x64)
Copyright (c) The PHP Group
Zend Engine v4.4.7, Copyright (c) Zend Technologies
with Zend OPcache v8.4.7, Copyright (c), by Zend Technologies
with Xdebug v3.4.1, Copyright (c) 2002-2025, by Derick Rethans
```
### Operating System
Windows10