We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have some code similar to this:
$return = match (true) { count($array) > 1 => $array[1], default => $array[0] ?? 'empty', };
Phpstan reports an offset error on $array[0].
$array[0]
https://phpstan.org/r/3f2b24c5-b3b3-4dcb-b46c-685973482e53
No errors should be given I think.
Phpstan really helps us maintaining our code quality to a reasonable level, thanks a lot!
The text was updated successfully, but these errors were encountered:
Yeah, this is probably a bug.
It works correctly with list type which you use should anyway: https://phpstan.org/r/221e19ac-7484-436b-8338-91e4a7f0b170
list
In non-list array, even when count($array) is 1, you don't have a guarantee that $array[0] exists.
count($array)
1
Sorry, something went wrong.
Thanks for the fix!
count($x) > $n === true
Fixed phpstan/phpstan-src#3037
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.
No branches or pull requests
Bug report
I have some code similar to this:
Phpstan reports an offset error on
$array[0]
.Code snippet that reproduces the problem
https://phpstan.org/r/3f2b24c5-b3b3-4dcb-b46c-685973482e53
Expected output
No errors should be given I think.
Did PHPStan help you today? Did it make you happy in any way?
Phpstan really helps us maintaining our code quality to a reasonable level, thanks a lot!
The text was updated successfully, but these errors were encountered: