- Add test case for foreach by value behavior when current element is removed - Verify that foreach maintains stable array snapshot during iteration - Confirm expected output matches array traversal before modifications - Document behavior where unset operations don't affect ongoing loop refactor(parser): simplify foreach array handling logic - Remove dedicated parseForeachArray method from ForeachTrait - Consolidate array iteration to use existing parseForeachIterable method - Maintain same functional behavior while reducing code duplication - Update type checking logic to route arrayspull/18/head
parent
aae4f2a07d
commit
324bf532bc
2 changed files with 30 additions and 20 deletions
@ -0,0 +1,29 @@ |
|||||||
|
--TEST-- |
||||||
|
foreach by value keeps a stable array snapshot when the current element is removed |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$values = ['a' => 1, 'b' => 2, 'c' => 3]; |
||||||
|
$seen = []; |
||||||
|
|
||||||
|
foreach ($values as $key => $value) { |
||||||
|
$seen[] = $key . ':' . $value; |
||||||
|
unset($values[$key]); |
||||||
|
} |
||||||
|
|
||||||
|
var_dump($seen); |
||||||
|
var_dump($values); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
array(3) { |
||||||
|
[0]=> |
||||||
|
string(3) "a:1" |
||||||
|
[1]=> |
||||||
|
string(3) "b:2" |
||||||
|
[2]=> |
||||||
|
string(3) "c:3" |
||||||
|
} |
||||||
|
array(0) { |
||||||
|
} |
||||||
Loading…
Reference in new issue