Skip to content

Fix phpstan/phpstan#13799: false positive on in_array(...) check with impure second argument#5141

Merged
VincentLanglet merged 2 commits intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-wjnkmpo
Mar 8, 2026
Merged

Fix phpstan/phpstan#13799: false positive on in_array(...) check with impure second argument#5141
VincentLanglet merged 2 commits intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-wjnkmpo

Conversation

@phpstan-bot
Copy link
Collaborator

@phpstan-bot phpstan-bot commented Mar 7, 2026

VincentLanglet and others added 2 commits March 7, 2026 11:49
- For non-constant arrays that might be empty (isIterableAtLeastOnce is not yes),
  return null (indeterminate) when the needle type is compatible with the haystack
  value type, since the array could be empty making in_array return false
- Still correctly reports "always false" when needle type is incompatible with
  haystack value type regardless of array emptiness
- Added regression test for the reported issue

Closes phpstan/phpstan#13799
@VincentLanglet VincentLanglet requested a review from staabm March 7, 2026 13:53
Copy link
Contributor

@staabm staabm left a comment

Choose a reason for hiding this comment

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

makes sense to me.

feels like the PR description no longer fits and the bots description should be removed?
(at least I think the change is not related to purity)

@VincentLanglet VincentLanglet merged commit 75596c3 into phpstan:2.1.x Mar 8, 2026
865 of 875 checks passed
@staabm staabm deleted the create-pull-request/patch-wjnkmpo branch March 8, 2026 10:10
uekann pushed a commit to uekann/phpstan-src that referenced this pull request Mar 9, 2026
…th impure second argument (phpstan#5141)

Co-authored-by: VincentLanglet <[email protected]>
Co-authored-by: Vincent Langlet <[email protected]>
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