New issue
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
Cannot find null pointer with array index access #2112
Comments
Mixed is mixed, it means that mixed can be passed everywhere. btw there is waiting PR that will introduce new rule that checks whether you have always fully typed iterables phpstan/phpstan-strict-rules#70 |
I think there's another open issue about this. Basically, we need to add value type to |
Another related case I got hit by today with level 4: It's a bit weird that EDIT: Using |
Hm, okay? Doesnt look related to me. This issue is about PHPStan assuming a value at some index is never NULL. If it was related to the one you linked, then moving the https://phpstan.org/r/8d999363-5ea6-41ad-93c8-7f00ce192a33 ... But I don't know the internals of these - so they might be related anyhow. Sorry if this causes noise for you. |
@eigan It's still unrelated to #2112. But I was mistaken. It's still reported even without the isset (https://phpstan.org/r/842c1e02-c375-4300-bd36-1bd2bf360ce8), but it's a feature. Since the array contains objects, This example https://phpstan.org/r/8d999363-5ea6-41ad-93c8-7f00ce192a33 looks like a real bug so please open a new issue for that. I'm locking this thread so that it doesn't veer off from the OP even more. |
Implemented: phpstan/phpstan-src@0f64ca7 + phpstan/phpstan-src@f74f05c |
Bug report
When a method have a return type of
array
will PHPStan not be able to find any potenial null pointers.Using
@return Foo[]
ongetFoos()
will resolve all issues in the snippet.Code snippet that reproduces the problem
https://phpstan.org/r/ec493869-6fbb-4511-99f7-3de3630c6297
Expected output
Edit: Updated the expected output, it said "
Foo|null
given". But PHPStan have no way of knowing it wasFoo
returned fromgetFoos()
, changed tomixed|null
The text was updated successfully, but these errors were encountered: