### Feature request I think we should be able to infer more precise array-shapes after if-casing the count() of a list-typed variable I expect no "Offset X might not exist" errors in https://phpstan.org/r/579e635a-3dc9-4a12-82cd-a4439a418213 ### Did PHPStan help you today? Did it make you happy in any way? _No response_
Activity
VincentLanglet commentedon Apr 14, 2026
Works fine when count is used inside the if.
https://phpstan.org/r/6cfd8a6f-6775-4ec8-bf56-9355fe6fc980
The issue is just the fact it's inside a variable
staabm commentedon Apr 14, 2026
yes, thats why its a dependent-types issue
Fix phpstan/phpstan#14464: Narrow list types when count() result is s…
phpstan-bot commentedon Apr 15, 2026
@staabm After the latest push in 2.2.x, PHPStan now reports different result with your code snippet:
Full report
Dumped type: list<non-empty-string>Dumped type: non-empty-list<non-empty-string>Dumped type: non-empty-list<non-empty-string>Dumped type: non-empty-list<non-empty-string>Dumped type: non-empty-list<non-empty-string>phpstan-bot commentedon Apr 15, 2026
@VincentLanglet After the latest push in 2.2.x, PHPStan now reports different result with your code snippet:
Full report
Dumped type: list<non-empty-string>Dumped type: array{non-empty-string, non-empty-string, non-empty-string}Dumped type: array{non-empty-string, non-empty-string}Dumped type: array{non-empty-string}Dumped type: list{0: non-empty-string, 1?: non-empty-string, 2?: non-empty-string}