Skip to content

Update PDOStatement stub#5132

Open
VincentLanglet wants to merge 3 commits intophpstan:2.1.xfrom
VincentLanglet:create-pull-request/patch-p7k2kkx
Open

Update PDOStatement stub#5132
VincentLanglet wants to merge 3 commits intophpstan:2.1.xfrom
VincentLanglet:create-pull-request/patch-p7k2kkx

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Mar 4, 2026

Rework of #5128

PDOStatement can either returns array, string or object based on the fetch mode
see phpstan/phpstan#14206 (comment),
so retricting the type to array is wrong ; rather than scalar|object|array, I think mixed will create less issues.

Fixes phpstan/phpstan#14206

Still ok with phpstan/phpstan#8886 since it just asked about Iterator.

phpstan-bot and others added 3 commits March 4, 2026 07:48
…reported as unresolvable

- When TypeNodeResolver creates an intersection of a non-generic iterable class with user-provided type arguments (e.g. PDOStatement<int,string>), TypeCombinator::intersect may collapse the result to NeverType if the iterable types are incompatible
- This was triggered by the more precise getIterator() return type in the PDOStatement stub (Iterator<mixed, array<int|string, mixed>> instead of plain Iterator)
- The fix preserves the IntersectionType directly when the intersection would otherwise collapse to NeverType, maintaining @var override semantics
- New regression test in tests/PHPStan/Rules/PhpDoc/data/bug-14206.php
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

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.

2 participants