1--TEST-- 2GH-112222: foreach by-ref may jump over keys during a rehash 3--FILE-- 4<?php 5 6// Not packed 7$a = ["k" => 0, 1 => 1, 2, 3, 4, 5, 6]; 8foreach ($a as $k => &$v) { 9 if ($k == 1) { 10 // force that it'll be rehashed by adding enough holes 11 unset($a[4], $a[5]); 12 // actually make the array larger than 8 elements to trigger rehash 13 $a[] = 8; $a[] = 9; $a[] = 10; 14 15 } 16 // observe the iteration jumping from key 1 to key 6, skipping keys 2 and 3 17 echo "$k => $v\n"; 18} 19 20?> 21--EXPECTF-- 22k => 0 231 => 1 242 => 2 253 => 3 266 => 6 277 => 8 288 => 9 299 => 10 30