You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect @var PDOStatement<int,string> contains unresolvable type #14206
When using a PDOStatement with mode PDO::FETCH_COLUMN I want to be able to type the statement with the appropriate type for the column, e.g. @var PDOStatement<int,string>.
For PHPStan versions up to 2.1.38, this works correctly and no errors are reported. From PHPStan 2.1.39 onwards, this now reports:
PHPDoc tag @var contains unresolvable type.
🪪 varTag.unresolvableType
Looking at the bot explanation, I understand more the issue now.
Something like PDOStatement<int,array<string>> works fine, the issue is related to PDOStatement<int,string> because
the template of PDOStatement is defined
class Test
{
public function test(PDO $db): void
{
$statement = $db->prepare('SELECT foo FROM bar');
$statement->setFetchMode(PDO::FETCH_COLUMN, 0);
$statement->execute();
}
}
and make the types aware to PHPStan without the need for additional inline @vars.
my feeling is in phpstan-src core we should use dumb-down types which are generic enough to support all possible use-cases.
since the most php database APIs (like PDO, mysqli, mysql,..) are stateful, its really hard to mirror them - the types depend on the used database backend, the global configuration of PDO etc (e.g. there is a global fetch mode).
thats why phpstan-dba exists in the first place.
I think we should strip down the builtin stub as much as necessary so it works with all relevant use-cases out of the box and tell people to use phpstan-dba when they want more magic/precise types out of the box.
Activity
VincentLanglet commentedon Feb 26, 2026
PDOStatement does not seems to be a generic
https://github.com/phpstan/phpstan-src/blob/ed40e65342856506cbc5e99bccb5853b941169a9/stubs/PDOStatement.stub#L8
So
PDOStatement<int,string>does not make sens currently. (and shouldn't work before even if it was not reported)staabm commentedon Feb 26, 2026
You could try https://github.com/staabm/phpstan-dba which will infer the types based on db schema
MacGritsch commentedon Mar 3, 2026
Same issue here: https://phpstan.org/r/c085525e-890d-4fc5-b6fd-6df79a8dea72
This used to work at least in version 2.1.32
MacGritsch commentedon Mar 3, 2026
My quick and dirty solution for my issue is to revert the change that was made in the stubs-file in version 2.1.39
staabm commentedon Mar 4, 2026
the simplified example from @MacGritsch regressed in 2.1.39 with
Fix phpstan/phpstan#14206: @var PDOStatement<int,string> incorrectly …
VincentLanglet commentedon Mar 4, 2026
Looking at the bot explanation, I understand more the issue now.
Something like
PDOStatement<int,array<string>>works fine, the issue is related toPDOStatement<int,string>becausethe template of PDOStatement is defined
with
getIteratorreturningIterator<mixed, array<int|string, mixed>>I'm not familiar with PDO Statement. But from my unstanding we'll have
So it shouldn't be
but
and we should just simplify to
Traversable<mixed>Best would be having the type restricted thanks to
setFetchMode; maybe withhttps://phpstan.org/writing-php-code/phpdocs-basics#change-type-of-current-object-after-calling-a-method
Until now
Could work (?) WDYT @staabm
staabm commentedon Mar 4, 2026
staabm/phpstan-dba would resolve the given example
and make the types aware to PHPStan without the need for additional inline
@vars.my feeling is in phpstan-src core we should use dumb-down types which are generic enough to support all possible use-cases.
since the most php database APIs (like PDO, mysqli, mysql,..) are stateful, its really hard to mirror them - the types depend on the used database backend, the global configuration of PDO etc (e.g. there is a global fetch mode).
thats why phpstan-dba exists in the first place.
I think we should strip down the builtin stub as much as necessary so it works with all relevant use-cases out of the box and tell people to use phpstan-dba when they want more magic/precise types out of the box.
phpstan-bot commentedon Mar 6, 2026
Closed via merging phpstan/phpstan-src#5132
github-actions commentedon Apr 7, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.