php-src/Zend/tests/gh12826.phpt
Niels Dossche b175ea4215 Fix GH-12826: Weird pointers issue in nested loops
This regressed in cd53ce838a.
The loop with `zend_hash_iterators_update` hangs forever because
`iter_pos` can't advance to idx. This is because the
`zend_hash_iterators_lower_pos` upper bound is `target->nNumUsed`,
but that is set to `source->nNumOfElements`.
That means that if there are holes in the array, we still loop over all
the buckets but the number of bucket slots will not match.
Fix it by changing the assignment.

Closes GH-12831.
2023-12-01 17:12:18 +01:00

31 lines
428 B
PHP

--TEST--
GH-12826 (Weird pointers issue in nested loops)
--FILE--
<?php
$test = array(
'a' => 1,
'b' => 2,
'c' => 3,
'd' => 4,
);
unset($test['a']);
unset($test['b']);
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 "\n";
}
unset($v);
?>
--EXPECT--
Pass c : 34
Pass d : 04