Skip to content

Fix phpstan/phpstan#13526: False positive with array_key_exists and union types#5114

Merged
staabm merged 1 commit intophpstan:2.1.xfrom
staabm:bug13526
Mar 1, 2026
Merged

Fix phpstan/phpstan#13526: False positive with array_key_exists and union types#5114
staabm merged 1 commit intophpstan:2.1.xfrom
staabm:bug13526

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Mar 1, 2026

Fixes phpstan/phpstan#13526

Related to #3933


if ($originalExprType->equals($nativeType)) {
$newType = TypeCombinator::intersect($type, $originalExprType);
if ($newType->isConstantScalarValue()->yes() && $newType->equals($originalExprType)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code was added in the past to improve performance.

after measuring again it seems we no longer need this logic, as it seems we fixed the bottleneck somewhere else.

before this PR

➜  phpstan-src git:(2.1.x) hyperfine 'vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php' --runs=3 --warmup=1
Benchmark 1: vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php
  Time (mean ± σ):     15.854 s ±  0.095 s    [User: 15.462 s, System: 0.383 s]
  Range (min … max):   15.749 s … 15.934 s    3 runs

with deleted logic

➜  phpstan-src git:(bug13526) hyperfine 'vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php' --runs=3 --warmup=1
Benchmark 1: vendor/bin/phpunit tests/PHPStan/Analyser/AnalyserIntegrationTest.php
  Time (mean ± σ):     15.840 s ±  0.213 s    [User: 15.455 s, System: 0.375 s]
  Range (min … max):   15.642 s … 16.065 s    3 runs

@staabm staabm marked this pull request as ready for review March 1, 2026 14:43
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm staabm merged commit 8eb56e5 into phpstan:2.1.x Mar 1, 2026
637 of 648 checks passed
@staabm staabm deleted the bug13526 branch March 1, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants