Skip to content

[CodingStyle] Deprecate ArraySpreadInsteadOfArrayMergeRector - #8277

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-array-spread-instead-of-array-merge
Aug 3, 2026
Merged

[CodingStyle] Deprecate ArraySpreadInsteadOfArrayMergeRector#8277
TomasVotruba merged 1 commit into
mainfrom
deprecate-array-spread-instead-of-array-merge

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Aug 3, 2026

Copy link
Copy Markdown
Member

This rule caused troubles as far as I can remember. Also, it makes code harder to read in half of the cases.
Not a rule we can apply generaly.


Deprecates ArraySpreadInsteadOfArrayMergeRector.

The rule turns readable array_merge() calls into spread arrays. That is a personal preference, not a fix: the result is harder to read and the ... in the middle of an array literal looks dangerous to reviewers.

-$values = array_merge($firstValues, $secondValues);
+$values = [...$firstValues, ...$secondValues];

The rule was not part of any set or level, so nothing else changes. It now implements DeprecatedInterface and throws on use; its tests and fixtures are removed.

…onal preference that makes array merges harder to read
@TomasVotruba
TomasVotruba merged commit 952266b into main Aug 3, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-array-spread-instead-of-array-merge branch August 3, 2026 15:19
@simonschaufi

simonschaufi commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

People have to get used to newer PHP syntax sooner or later. PHP 8.5 introduces the pipe operator |> and PHP 8.6 continues in that direction with placement markers ?. You personally may not like this direction but this is how PHP evolves and this is the fancy new php code style that is the future:

$uniqueEmails = $userRepository->findAll()
|> array_filter(?, fn($u) => $u->isActive())
|> array_map(fn($u) => $u->getEmail(), ?)
|> array_map(strtolower(...), ?)
|> array_unique(...);

array_merge is slow and the spread operator is the better way to use so I'm sad this rule got deprecated.

@TomasVotruba

Copy link
Copy Markdown
Member Author

Pipe operators have also drawbacks based on PHP version - https://stitcher.io/blog/php-86-partial-function-application, so they should be used willingly. Same was for spread operator ... that handles keys different in 2 PHP versions. Very dangerous for projects that are not on latest version yet. Feel free to make custom rule to handle spread within pipes.

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.

2 participants