Closed
Description
Description
Hi,
I observe a weird issue in php 8.3.0 with the following (weird) code:
<?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