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
Wrong return type #1903
Comments
phpstan.org reproduction (please always include it): https://phpstan.org/r/8e8c10ec-47bf-4868-b8d4-3d5446d9950e BTW: Your code is wrong, the right expectation is:
Not "no errors". |
Yes, of course. All you said is right. I will remember next time about reproduction link and yes for that example expectation error should be what you said. I just modified my original big file and set INT instead of []. Still, problem with null shouldnt appear :) Ta |
And maybe you should not compare to null, but check if key existence via isset/array_key_exists. I added expected phpdoc of property and there is output: |
@CzechBoy yes, in this current simple example you could have a right but I just cutted it from bigger context where there was null value |
ok, here is update |
Ok, let me show you full class without any cutting The last error This is not my class, I just run phpstan on one of our projects and I found that problem. But now when I check once more that class I do not understand why there is comparing to null. There should be as you said just checking isset. When I replace it to checking isset then that problem do not appear so thank you for that. but still I think there is some problem with phpstan analysing for my original example from first post, dont you think? |
Yes, definitely, the original example is sufficient to reproduce this, thanks. |
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. |
Hi, I have a function which returns an array but phpstan says, it returns null
This is the code:
As you can see it always returns an array. I think that first IF block confuses phpstan somehow
Expected output
There shouldnt be any error for that class
The text was updated successfully, but these errors were encountered: