-
Notifications
You must be signed in to change notification settings - Fork 555
Fix phpstan/phpstan#14275: Variable passed by reference are not updated #5217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ondrejmirtes
merged 10 commits into
phpstan:2.1.x
from
phpstan-bot:create-pull-request/patch-qqhkbas
Mar 20, 2026
+123
−2
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a7828a6
Fix phpstan/phpstan#14275: Propagate type changes through variable re…
VincentLanglet dc2896b
Add regression test for phpstan/phpstan#8056
phpstan-bot c24f3c2
Re-register intertwined variable entries after propagation for subseq…
phpstan-bot a0ce7cc
Fix reference type propagation for subsequent assignments
phpstan-bot 18648a0
Simplify reference propagation: prevent invalidation instead of re-re…
phpstan-bot e0e4157
Fix reference propagation to use chain tracking instead of boolean flag
phpstan-bot 3ded2f5
Add rule test for bug 8056 to verify no false positive "Empty array p…
phpstan-bot 9e14628
Refactor: extract isSimpleVariableReference() method on IntertwinedVa…
phpstan-bot 511e73e
Fix coding standards: use imports instead of fully qualified names in…
phpstan-bot 0827af5
Rename isSimpleVariableReference() to isVariableToVariableReference()…
phpstan-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug14275; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| // Basic reference: modifying $b should update $a | ||
| $a = []; | ||
| $b = &$a; | ||
|
|
||
| $b[0] = 1; | ||
| assertType('array{1}', $a); | ||
| assertType('array{1}', $b); | ||
|
|
||
| // Reference with scalar reassignment | ||
| $c = 1; | ||
| $d = &$c; | ||
| $d = 2; | ||
| assertType('2', $c); | ||
| assertType('2', $d); | ||
|
|
||
| // Reference with different type reassignment | ||
| $e = 'hello'; | ||
| $f = &$e; | ||
| $f = 42; | ||
| assertType('42', $e); | ||
| assertType('42', $f); | ||
|
|
||
| // Subsequent assignments should continue propagating | ||
| $e = 22; | ||
| assertType('22', $e); | ||
| assertType('22', $f); | ||
|
|
||
| $f = 33; | ||
| assertType('33', $e); | ||
| assertType('33', $f); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug8056; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| $array = []; | ||
| $tmp = &$array; | ||
| $tmp[] = 'foo'; | ||
|
|
||
| assertType("array{'foo'}", $array); | ||
| assertType("array{'foo'}", $tmp); | ||
|
|
||
| foreach ($array as $i) { | ||
| assertType("'foo'", $i); | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug8056Rule; | ||
|
|
||
| $array = []; | ||
| $tmp = &$array; | ||
| $tmp[] = 'foo'; | ||
|
|
||
| foreach ($array as $i) { | ||
|
|
||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.