-
Notifications
You must be signed in to change notification settings - Fork 555
Fix phpstan/phpstan#14319: PHPStan takes extremely long analyzing if-offset checks on array|object
#5242
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
VincentLanglet
merged 10 commits into
phpstan:2.1.x
from
phpstan-bot:create-pull-request/patch-cltr70w
Mar 18, 2026
+114
−1
Merged
Fix phpstan/phpstan#14319: PHPStan takes extremely long analyzing if-offset checks on array|object
#5242
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
515ab71
Fix phpstan/phpstan#14319: Prevent exponential type growth in array d…
phpstan-bot 5f328aa
simplify fix
staabm a94df70
Only count HasOffsetValueType accessories for complexity limit
phpstan-bot f4ed06f
simplify
staabm fa17836
Update bug-14319.php
staabm d5aaa3f
cs
staabm fcec2e3
Update MutatingScope.php
staabm 87f29af
Update MutatingScope.php
staabm 879291b
degrade only maybe-arrays
staabm e151f73
Rename $tooComplex to $tooManyHasOffsetValueTypes for clarity
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
|
|
||
| namespace Bug14319; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| function foo(string $a, int $b): array|object | ||
| { | ||
| return $a; | ||
| } | ||
|
|
||
|
|
||
| final class test | ||
| { | ||
| protected function edit(int|string|null $IdNum = null): void | ||
| { | ||
| $rows = foo("SELECT *", $IdNum); | ||
| assertType('array|object', $rows); | ||
|
|
||
| if ($_POST['edycja'] === 'edycja' ) { | ||
| $raport = ''; | ||
| if ($rows['rap_tr']) { | ||
| $raport .= 'T: '.$rows['rap_tr'].", \n"; | ||
| } | ||
| if ($rows['rap_ks']) { | ||
| $raport .= 'K: '.$rows['rap_ks'].", \n"; | ||
| } | ||
| if ($rows['rap_br']) { | ||
| $raport .= 'B: '.$rows['rap_br'].", \n"; | ||
| } | ||
| if ($rows['rap_cz']) { | ||
| $raport .= 'C: '.$rows['rap_cz'].", \n"; | ||
| } | ||
| if ($rows['rap_fil']) { | ||
| $raport .= 'Fil: '.$rows['rap_fil'].", \n"; | ||
| } | ||
| if ($rows['rap_roz']) { | ||
| $raport .= 'Roz: '.$rows['rap_roz'].", \n"; | ||
| } | ||
| if ($rows['rap_roz2']) { | ||
| $raport .= 'Roz: '.$rows['rap_roz2'].", \n"; | ||
| } | ||
| if ($rows['rap_roz3']) { | ||
| $raport .= 'Roz: '.$rows['rap_roz3'].", \n"; | ||
| } | ||
| assertType("(non-empty-array&hasOffsetValue('rap_br', mixed)&hasOffsetValue('rap_ks', mixed)&hasOffsetValue('rap_tr', mixed))|(ArrayAccess&hasOffsetValue('rap_br', 0|0.0|''|'0'|array{}|false|null)&hasOffsetValue('rap_ks', 0|0.0|''|'0'|array{}|false|null)&hasOffsetValue('rap_tr', 0|0.0|''|'0'|array{}|false|null))|(ArrayAccess&hasOffsetValue('rap_br', 0|0.0|''|'0'|array{}|false|null)&hasOffsetValue('rap_ks', 0|0.0|''|'0'|array{}|false|null)&hasOffsetValue('rap_tr', mixed~(0|0.0|''|'0'|array{}|false|null)))|(ArrayAccess&hasOffsetValue('rap_br', 0|0.0|''|'0'|array{}|false|null)&hasOffsetValue('rap_ks', mixed~(0|0.0|''|'0'|array{}|false|null))&hasOffsetValue('rap_tr', 0|0.0|''|'0'|array{}|false|null))|(ArrayAccess&hasOffsetValue('rap_br', 0|0.0|''|'0'|array{}|false|null)&hasOffsetValue('rap_ks', mixed~(0|0.0|''|'0'|array{}|false|null))&hasOffsetValue('rap_tr', mixed~(0|0.0|''|'0'|array{}|false|null)))|(ArrayAccess&hasOffsetValue('rap_br', mixed~(0|0.0|''|'0'|array{}|false|null))&hasOffsetValue('rap_ks', 0|0.0|''|'0'|array{}|false|null)&hasOffsetValue('rap_tr', 0|0.0|''|'0'|array{}|false|null))|(ArrayAccess&hasOffsetValue('rap_br', mixed~(0|0.0|''|'0'|array{}|false|null))&hasOffsetValue('rap_ks', 0|0.0|''|'0'|array{}|false|null)&hasOffsetValue('rap_tr', mixed~(0|0.0|''|'0'|array{}|false|null)))|(ArrayAccess&hasOffsetValue('rap_br', mixed~(0|0.0|''|'0'|array{}|false|null))&hasOffsetValue('rap_ks', mixed~(0|0.0|''|'0'|array{}|false|null))&hasOffsetValue('rap_tr', 0|0.0|''|'0'|array{}|false|null))|(ArrayAccess&hasOffsetValue('rap_br', mixed~(0|0.0|''|'0'|array{}|false|null))&hasOffsetValue('rap_ks', mixed~(0|0.0|''|'0'|array{}|false|null))&hasOffsetValue('rap_tr', mixed~(0|0.0|''|'0'|array{}|false|null)))", $rows); | ||
| } | ||
| } | ||
| } |
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,39 @@ | ||
| <?php | ||
|
|
||
| namespace BenchBug14319; | ||
staabm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function foo(string $a, int $b): array|object | ||
| { | ||
| return $a; | ||
| } | ||
|
|
||
|
|
||
| final class test | ||
| { | ||
| protected function edit(int|string|null $IdNum = null): void | ||
| { | ||
| $rows = foo("SELECT *", $IdNum); | ||
|
|
||
| if ($_POST['edycja'] === 'edycja' ) { | ||
| $raport = ''; | ||
| if ($rows['rap_tr']) { | ||
| $raport .= 'T: '.$rows['rap_tr'].", \n"; | ||
| } | ||
| if ($rows['rap_ks']) { | ||
| $raport .= 'K: '.$rows['rap_ks'].", \n"; | ||
| } | ||
| if ($rows['rap_br']) { | ||
| $raport .= 'B: '.$rows['rap_br'].", \n"; | ||
| } | ||
| if ($rows['rap_cz']) { | ||
| $raport .= 'C: '.$rows['rap_cz'].", \n"; | ||
| } | ||
| if ($rows['rap_fil']) { | ||
| $raport .= 'Fil: '.$rows['rap_fil'].", \n"; | ||
| } | ||
| if ($rows['rap_roz']) { | ||
| $raport .= 'Roz: '.$rows['rap_roz'].", \n"; | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The var name si too vague.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Renamed
$tooComplexto$tooManyHasOffsetValueTypesto better describe what the variable tracks — whether the union type has exceeded the limit ofHasOffsetValueTypeaccessory types. All tests pass (11602 tests) and static analysis reports no errors.