[Php71] Skip AssignArrayToStringRector on a variable re-assigned as string - #8293
Merged
TomasVotruba merged 2 commits intoAug 5, 2026
Merged
Conversation
TomasVotruba
enabled auto-merge (squash)
August 5, 2026 09:36
…tring
PHPStan 2.2.8 infers a possibly undefined variable as ErrorType, where it used to be a union of its possible types. AssignArrayToStringRector leaned on that union to skip:
if (empty($where)) {
$where = '';
} else {
$where = 'WHERE ' . implode(' AND ', $where);
}
With ErrorType, neither the isArray() nor the UnionType guard matches, and the empty string turned into an array, breaking the concat that follows.
The variable being filled as a string later on is what makes it a string here, so that is now checked directly. An empty string assign does not count, as it is a candidate for the very same re-type.
TomasVotruba
force-pushed
the
fix-assign-array-to-string-reassigned-as-string
branch
from
August 5, 2026 10:03
5cf4efd to
b2ebd76
Compare
rectorphp/rector-symfony#1010 trims TwigSetProvider to its composer-based trigger, as every rule of the per-version Twig sets is already in it, bound to the twig/twig version it needs.
TomasVotruba
deleted the
fix-assign-array-to-string-reassigned-as-string
branch
August 5, 2026 10:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Main is red on
AssignArrayToStringRectorTest, fixtureskip_reassigned_as_string.php.inc. Not caused by any commit here — phpstan/phpstan 2.2.8 was released, and CI resolves it while a localvendor/still on 2.2.7 stays green. Reproducible withcomposer update phpstan/phpstan.2.2.8 infers a possibly undefined variable as
ErrorType, where it used to report a union of its possible types. The rule leaned on that union:Neither the
isArray()nor theUnionTypeguard matches anErrorType, so the empty string became an array and broke the concatenation below:if (empty($where)) { - $where = ''; + $where = []; } else { $where = 'WHERE ' . implode(' AND ', $where); }Guarding on
ErrorTypeis not the fix — a first assignment like$string = '';reports*ERROR*for the same reason, and those must keep converting.What actually makes
$wherea string here is that it is assigned a string further down, so the rule now checks exactly that. An empty string assign does not count as proof, since it is itself a candidate for the same re-type — that keepsfixture.php.incconverting its second$string = '';.Full suite green on 2.2.8: 5372 tests, 6884 assertions.
Second commit
SetManagerTeststill expected 8 Twig composer-triggered sets. rectorphp/rector-symfony#1010 is merged, soTwigSetProvidernow registers only its composer-based trigger — every rule of the per-version Twig sets is already in it, bound to thetwig/twigversion it needs. Folded in here so this PR is green on its own; it was #8294, now closed.