mirror of
https://github.com/php/php-src.git
synced 2026-04-19 14:01:01 +02:00
Merge branch 'PHP-7.3'
* PHP-7.3: Fixed bug #76800 (foreach inconsistent if array modified during loop)
This commit is contained in:
13
Zend/tests/bug76800.phpt
Normal file
13
Zend/tests/bug76800.phpt
Normal file
@@ -0,0 +1,13 @@
|
||||
--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
|
||||
@@ -1179,9 +1179,11 @@ ZEND_API int ZEND_FASTCALL zend_hash_rehash(HashTable *ht)
|
||||
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++;
|
||||
|
||||
Reference in New Issue
Block a user