[php-src] Issue #12826: Weird pointers issue in nested loops
| From: | bloatware | Date: | Wed, 29 Nov 2023 10:44:16 +0000 |
| Subject: | [php-src] Issue #12826: Weird pointers issue in nested loops | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245930@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12826
Author: bloatware
### Description
Hi,
I observe a weird issue in php 8.3.0 with the following (weird) code:
```php
<?php
$test = array(
'a' => 1,
'b' => 2,
'c' => 3,
'd' => 4,
);
//unset($test['a']);
//unset($test['b']);
//unset($test['c']);
//unset($test['d']);
foreach($test as $k => &$v) { // Mind the reference!
echo "Pass $k : ";
foreach($test as $kk => $vv) {
echo $test[$kk];
if ($kk == $k) $test[$kk] = 0;
}
echo '<br />';
}
unset($v);
```
As expected, it outputs:
```
Pass a : 1234
Pass b : 0234
Pass c : 0034
Pass d : 0004
```
But if I unset, say
$test['a'] and $test['b'] before
the loop, the server seems to enter some kind of infinite loop. Unsetting only *one* element or only
few *last* elements does not seem to yield any problem. When looping by value $k =>
$v everything is fine of course.
The problem seems to come from $test[$kk] = 0 assignment. If I comment it out,
everything is fine again, whichever elements are unset.
I've tested it on few servers, with the same result. The code works without any issue in php
from 5.4 to 8.2.
### PHP Version
PHP 8.3.0
### Operating System
Various