php-src/Zend/tests/gh13178_2.phpt
Ilija Tovilo d653646841
Fix iterator position resetting
Previously, when an array was converted from packed to hashed, iterators would
not be correctly reset to 0. Similarly, removing the last element from an array
would decrease nNumUsed but not actually fix the iterator position, causing the
element to be skipped in the next iteration.

Some code was also removed that skips over IS_UNDEF elements for
nInternalPointer and iterator positions. This is unnecessary, as this already
happens during iteration.

Closes GH-13178
Closes GH-13188
2024-01-21 23:24:00 +01:00

27 lines
375 B
PHP

--TEST--
GH-13178: Unsetting last offset must floor iterator position
--FILE--
<?php
$array = [100 => 'foo'];
foreach ($array as $key => &$value) {
var_dump($key);
unset($array[$key]);
$array[] = 'foo';
if ($key === 110) {
break;
}
}
?>
--EXPECT--
int(100)
int(101)
int(102)
int(103)
int(104)
int(105)
int(106)
int(107)
int(108)
int(109)
int(110)