Skip to content

[CodeQuality] Deprecate ForeachItemsAssignToEmptyArrayToAssignRector - #8577

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-deprecate-foreach-items-assign
Oct 10, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-deprecate-foreach-items-assign

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Deprecate ForeachItemsAssignToEmptyArrayToAssignRector.

The foreach-append and the direct array assign are not equivalent. The foreach re-indexes keys from 0, while the direct assign keeps the original keys:

$items = [3 => 'a', 7 => 'b'];
// loop:       [0 => 'a', 1 => 'b']
// assignment: [3 => 'a', 7 => 'b']

This can create risky situations with sparse arrays, so the rule is deprecated.

… as it re-indexes array keys and can create risky situations
@TomasVotruba
TomasVotruba merged commit 20418d1 into main Oct 10, 2026
50 checks passed
@TomasVotruba
TomasVotruba deleted the tv-deprecate-foreach-items-assign branch October 10, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant