You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ForeachToArrayAllRector breaks code that increments an outer variable inside the loop #9961
ForeachToArrayAllRector moves a $i++ from the loop body into an arrow function. Arrow functions capture outer variables by value, so the increment no longer persists between iterations and the result changes.
With $items = [1, 2] and $others = [1, 2], the original code returns true and the refactored code returns false: every call reads $others[0].
Expected Behaviour
Skip the refactoring when the loop body modifies an outer variable (++, --, assignment, compound assignment), because the arrow function cannot propagate that change.
Activity
samsonasik commentedon Nov 6, 2026
I created PR:
for it.