|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2018, PHP 7.2.11
+- Core:
+ . Fixed bug #76800 (foreach inconsistent if array modified during loop).
+ (Dmitry)
+
- Opcache:
. Fixed bug #76832 (ZendOPcache.MemoryBase periodically deleted by the OS).
(Anatol)
--- /dev/null
+--TEST--
+Bug #76800 (foreach inconsistent if array modified during loop)
+--FILE--
+<?php
+$arr = [1 => 1, 3 => 3]; // [1 => 1, 2 => 3] will print both keys
+foreach($arr as $key => &$val) { // without & will print both keys
+ echo "See key {$key}\n";
+ $arr[0] = 0; // without this line will print both keys
+ unset($arr[0]);
+}
+--EXPECT--
+See key 1
+See key 3
if (UNEXPECTED(ht->nInternalPointer == i)) {
ht->nInternalPointer = j;
}
- if (UNEXPECTED(i == iter_pos)) {
- zend_hash_iterators_update(ht, i, j);
- iter_pos = zend_hash_iterators_lower_pos(ht, iter_pos + 1);
+ if (UNEXPECTED(i >= iter_pos)) {
+ do {
+ zend_hash_iterators_update(ht, iter_pos, j);
+ iter_pos = zend_hash_iterators_lower_pos(ht, iter_pos + 1);
+ } while (iter_pos < i);
}
q++;
j++;