[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Tue, 15 Sep 2026 16:59:37 +0000
Subject: [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141209@lists.php.net to get a copy of this message
Author: Weilin Du (LamentXU123) Date: 2026-09-16T00:44:01+08:00 Commit: https://github.com/php/php-src/commit/7d796b7dbf9e2800c711277e72d5913500576319 Raw diff: https://github.com/php/php-src/commit/7d796b7dbf9e2800c711277e72d5913500576319.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: Revert Zend: Fix iterator relocation at the current element during rehash in 8.4 and 8.5 Changed paths: D Zend/tests/array_dup_internal_pointer_hole.phpt D Zend/tests/array_dup_iterator_past_end.phpt D Zend/tests/array_dup_multiple_iterators.phpt D Zend/tests/rehash_multiple_iterators.phpt M NEWS M Zend/zend_hash.c Diff: diff --git a/NEWS b/NEWS index 811893eff588..e1b86f47533e 100644 --- a/NEWS +++ b/NEWS @@ -3,8 +3,6 @@ PHP NEWS ?? ??? ????, PHP 8.5.12 - Core: - . Fixed incorrect internal pointer and foreach iterator positions when - compacting arrays with holes. (Weilin Du) . Fixed bug GH-23644 (Optimizer leaves a constant-vs-constant comparison unfolded, crashing the VM in zval_undefined_cv). (ndossche) diff --git a/Zend/tests/array_dup_internal_pointer_hole.phpt b/Zend/tests/array_dup_internal_pointer_hole.phpt deleted file mode 100644 index 97fdd40bb1ad..000000000000 --- a/Zend/tests/array_dup_internal_pointer_hole.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -Array duplication relocates an internal pointer on a hole, with and without foreach iterators ---FILE-- -<?php -function duplicate(array &$values): void { - $copy = $values; - $values['i'] = 18; - echo 'current: ', key($values), '=>', current($values), "\n"; - next($values); - echo 'next: ', key($values), '=>', current($values), "\n"; - echo 'copy current: ', key($copy), '=>', current($copy), "\n"; - echo 'copy keys: ', implode(' ', array_keys($copy)), "\n"; -} - -foreach ([false, true] as $withIterator) { - echo $withIterator ? "With iterator:\n" : "Without iterator:\n"; - $values = ['a' => 10, 'b' => 11, 'c' => 12, 'd' => 13, - 'e' => 14, 'f' => 15, 'g' => 16, 'h' => 17]; - next($values); - next($values); - // Leave the internal pointer on a hole before several surviving elements. - unset($values['a'], $values['b'], $values['c'], $values['d']); - - if ($withIterator) { - foreach ($values as &$value) { - duplicate($values); - break; - } - unset($value); - } else { - duplicate($values); - } -} -?> ---EXPECT-- -Without iterator: -current: e=>14 -next: f=>15 -copy current: e=>14 -copy keys: e f g h -With iterator: -current: e=>14 -next: f=>15 -copy current: e=>14 -copy keys: e f g h diff --git a/Zend/tests/array_dup_iterator_past_end.phpt b/Zend/tests/array_dup_iterator_past_end.phpt deleted file mode 100644 index 80e52e3e5ab2..000000000000 --- a/Zend/tests/array_dup_iterator_past_end.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Array duplication preserves past-the-end iterators when compacting holes ---FILE-- -<?php -$values = ['a' => 10, 'b' => 11, 'c' => 12, 'd' => 13]; -unset($values['a'], $values['b']); - -foreach ($values as $key => &$value) { - echo "$key=>$value\n"; - if ($key === 'd') { - // The iterator is one past the end; COW compacts the preceding holes. - $copy = $values; - $values['e'] = 14; - } -} -unset($value); -echo 'copy: ', implode(' ', array_keys($copy)), "\n"; -?> ---EXPECT-- -c=>12 -d=>13 -e=>14 -copy: c d diff --git a/Zend/tests/array_dup_multiple_iterators.phpt b/Zend/tests/array_dup_multiple_iterators.phpt deleted file mode 100644 index 96f2dbb7f8de..000000000000 --- a/Zend/tests/array_dup_multiple_iterators.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -Array duplication updates iterators at both a hole and the next defined element ---FILE-- -<?php -function test(array $values): void { - $outerVisits = []; - $innerVisits = []; - $first = true; - foreach ($values as $outerKey => &$outerValue) { - $outerVisits[] = "$outerKey=>$outerValue"; - if ($first) { - $first = false; - foreach ($values as $innerKey => &$innerValue) { - $innerVisits[] = "$innerKey=>$innerValue"; - if ($innerValue === 11) { - // The outer cursor is at a hole, the inner at the next value. - unset($values['a'], $values['b']); - $copy = $values; - // Trigger copy-on-write duplication, which compacts the holes. - $values['i'] = 18; - } - } - unset($innerValue); - } - } - unset($outerValue); - echo 'outer: ', implode(' ', $outerVisits), "\n"; - echo 'inner: ', implode(' ', $innerVisits), "\n"; - echo 'copy: ', implode(' ', array_keys($copy)), "\n"; -} - -test(['a' => 10, 'b' => 11, 'c' => 12, 'd' => 13, - 'e' => 14, 'f' => 15, 'g' => 16, 'h' => 17]); -?> ---EXPECT-- -outer: a=>10 c=>12 d=>13 e=>14 f=>15 g=>16 h=>17 i=>18 -inner: a=>10 b=>11 c=>12 d=>13 e=>14 f=>15 g=>16 h=>17 i=>18 -copy: c d e f g h diff --git a/Zend/tests/rehash_multiple_iterators.phpt b/Zend/tests/rehash_multiple_iterators.phpt deleted file mode 100644 index cbbfc75d703a..000000000000 --- a/Zend/tests/rehash_multiple_iterators.phpt +++ /dev/null @@ -1,40 +0,0 @@ ---TEST-- -Rehashing updates iterators at both a hole and the next defined element ---FILE-- -<?php -function test(array $values, $firstKey, $secondKey, $newKey, int $newValue): void { - $outerVisits = []; - $innerVisits = []; - $first = true; - foreach ($values as $outerKey => &$outerValue) { - $outerVisits[] = "$outerKey=>$outerValue"; - if ($first) { - $first = false; - foreach ($values as $innerKey => &$innerValue) { - $innerVisits[] = "$innerKey=>$innerValue"; - if ($innerValue === 11) { - // The outer cursor is at a hole, the inner at the next value. - unset($values[$firstKey], $values[$secondKey]); - $values[$newKey] = $newValue; - } - } - unset($innerValue); - } - } - unset($outerValue); - echo 'outer: ', implode(' ', $outerVisits), "\n"; - echo 'inner: ', implode(' ', $innerVisits), "\n"; -} - -// Adding a string key converts packed storage and compacts its holes. -test([10, 11, 12, 13, 14], 0, 1, 'new', 15); - -// Inserting into a full mixed table compacts its holes without growing it. -test(['a' => 10, 'b' => 11, 'c' => 12, 'd' => 13, - 'e' => 14, 'f' => 15, 'g' => 16, 'h' => 17], 'a', 'b', 'i', 18); -?> ---EXPECT-- -outer: 0=>10 2=>12 3=>13 4=>14 new=>15 -inner: 0=>10 1=>11 2=>12 3=>13 4=>14 new=>15 -outer: a=>10 c=>12 d=>13 e=>14 f=>15 g=>16 h=>17 i=>18 -inner: a=>10 b=>11 c=>12 d=>13 e=>14 f=>15 g=>16 h=>17 i=>18 diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index c90887ed7c43..b8c33548f930 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -1411,7 +1411,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_rehash(HashTable *ht) do { zend_hash_iterators_update(ht, iter_pos, j); iter_pos = zend_hash_iterators_lower_pos(ht, iter_pos + 1); - } while (iter_pos <= i); + } while (iter_pos < i); } q++; j++; @@ -2407,7 +2407,7 @@ static zend_always_inline uint32_t zend_array_dup_elements(const HashTable *sour if (EXPECTED(!HT_HAS_ITERATORS(target))) { while (p != end) { if (zend_array_dup_element(source, target, target_idx, p, q, 0, static_keys, with_holes)) { - if (UNEXPECTED(target->nInternalPointer > target_idx && target->nInternalPointer <= idx)) { + if (source->nInternalPointer == idx) { target->nInternalPointer = target_idx; } target_idx++; q++; @@ -2420,21 +2420,19 @@ static zend_always_inline uint32_t zend_array_dup_elements(const HashTable *sour while (p != end) { if (zend_array_dup_element(source, target, target_idx, p, q, 0, static_keys, with_holes)) { - if (UNEXPECTED(target->nInternalPointer > target_idx && target->nInternalPointer <= idx)) { + if (source->nInternalPointer == idx) { target->nInternalPointer = target_idx; } if (UNEXPECTED(idx >= iter_pos)) { do { zend_hash_iterators_update(target, iter_pos, target_idx); iter_pos = zend_hash_iterators_lower_pos(target, iter_pos + 1); - } while (iter_pos <= idx); + } while (iter_pos < idx); } target_idx++; q++; } idx++; p++; } - /* Move past-the-end iterators so they can pick up newly appended elements. */ - _zend_hash_iterators_update(target, source->nNumUsed, target_idx); } return target_idx; }

« previous php.cvs (#141209) next »