@@ -1506,10 +1506,11 @@ public function processStmtNode(
15061506 $ originalStorage = $ storage ;
15071507 $ unrolledEndScope = null ;
15081508 $ unrolledTotalKeys = null ;
1509+ $ iterateeScope = $ this ->polluteScopeWithAlwaysIterableForeach ? $ scope ->filterByTruthyValue ($ arrayComparisonExpr ) : $ scope ;
15091510 if ($ context ->isTopLevel ()) {
15101511 $ storage = $ originalStorage ->duplicate ();
15111512
1512- $ originalScope = $ this -> polluteScopeWithAlwaysIterableForeach ? $ scope -> filterByTruthyValue ( $ arrayComparisonExpr ) : $ scope ;
1513+ $ originalScope = $ iterateeScope ;
15131514 $ unrolledResult = $ this ->tryProcessUnrolledConstantArrayForeach ($ stmt , $ originalScope , $ originalStorage , $ context );
15141515 if ($ unrolledResult !== null ) {
15151516 $ bodyScope = $ unrolledResult ['bodyScope ' ];
@@ -1520,7 +1521,7 @@ public function processStmtNode(
15201521 $ count = 0 ;
15211522 do {
15221523 $ prevScope = $ bodyScope ;
1523- $ bodyScope = $ bodyScope ->mergeWith ($ this -> polluteScopeWithAlwaysIterableForeach ? $ scope -> filterByTruthyValue ( $ arrayComparisonExpr ) : $ scope );
1524+ $ bodyScope = $ bodyScope ->mergeWith ($ iterateeScope );
15241525 $ storage = $ originalStorage ->duplicate ();
15251526 $ bodyScope = $ this ->enterForeach ($ bodyScope , $ storage , $ originalScope , $ stmt , $ nodeCallback );
15261527 $ bodyScopeResult = $ this ->processStmtNodesInternal ($ stmt , $ stmt ->stmts , $ bodyScope , $ storage , new NoopNodeCallback (), $ context ->enterDeep ())->filterOutLoopExitPoints ();
@@ -1540,7 +1541,7 @@ public function processStmtNode(
15401541 }
15411542 }
15421543
1543- $ bodyScope = $ bodyScope ->mergeWith ($ this -> polluteScopeWithAlwaysIterableForeach ? $ scope -> filterByTruthyValue ( $ arrayComparisonExpr ) : $ scope );
1544+ $ bodyScope = $ bodyScope ->mergeWith ($ iterateeScope );
15441545 $ storage = $ originalStorage ;
15451546 $ bodyScope = $ this ->enterForeach ($ bodyScope , $ storage , $ originalScope , $ stmt , $ nodeCallback );
15461547 $ finalPassContext = $ unrolledTotalKeys !== null ? $ context ->enterUnrolledForeach ($ unrolledTotalKeys ) : $ context ;
0 commit comments