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
preg_match param-out is a list, and phpstan kind of agrees, but not enough #12397
But that's not exactly a list, so it complains when I return that when a list<string> is expected.
I think it's impossible to get a $match where 0 and 2 are set, but 1 is not. And other non-list combinations. PregMatchParameterOutTypeExtension and RegexArrayShapeMatcher should know that.
This exact example is fine, because Phpstan doesn't complain about the return value, but without the if breakout, it does complain, and that's wrong IMO. Even without knowing the preg_match return value, we know that $match is a list.
Unless I am mistaken, and it IS possible to get a non-list array. But I don't think so. See Playground example too. Without the breakout if, Phpstan complains, even though an empty array is a perfectly valid list<string>. And after the if$match is a known list?? something is off here.
Did PHPStan help you today? Did it make you happy in any way?
/cc @staabm Is this true? If yes you can set the ConstantArrayType isList constructor argument. Also you can check what list{...} resolves to in TypeNodeResolver. It might be that, or it might be intersection with AccessoryArrayListType.
Activity
ondrejmirtes commentedon Jan 8, 2025
/cc @staabm Is this true? If yes you can set the ConstantArrayType isList constructor argument. Also you can check what
list{...}resolves to in TypeNodeResolver. It might be that, or it might be intersection with AccessoryArrayListType.staabm commentedon Jan 8, 2025
I need to double check. It at least depends on $flags I guess
github-actions commentedon Apr 25, 2025
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.
ondrejmirtes commentedon Feb 27, 2026
This wasn't actually fixed, it's exposed after phpstan/phpstan-src#4399 again
phpstan-bot commentedon Feb 27, 2026
@rudiedirkx After the latest push in 2.2.x, PHPStan now reports different result with your code snippet:
Full report
Dumped type: list{0?: string, 1?: non-falsy-string, 2?: numeric-string}Dumped type: array{non-falsy-string, non-falsy-string, numeric-string}phpstan-bot commentedon Mar 12, 2026
Closed via merging phpstan/phpstan-src#5209
github-actions commentedon Apr 13, 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.