-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
Optional array key is not recognized with !empty #3297
Comments
Sems like a very common use case - checking if a value exists and then using it. isset is handling this correctly, but changing
Works!: https://phpstan.org/r/2ae43dc1-4ec4-419f-8f43-7f4345b9e328 This would feel a bit wrong since empty has exactly this functionality... |
Could this be handled exactly the same way as |
It definitely can. Look for Isset_ handling in TypeSpecifier. |
Thanks for the pointer! I don't really understand the code yet, since I've never worked with code analyzers / parsers. But could the issue be here? For |
First try to write a failing test, probably in https://github.com/phpstan/phpstan-src/blob/master/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php. And then try to do whatever you think should work :) |
Thanks for your pointers @ondrejmirtes! Even though I still don't understand the code well, I created a failing test and fixed it. Hopefully the PR is ok (and lets see if the whole CI pipeline passes :) ). |
Fixed by: phpstan/phpstan-src#569 |
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. |
Bug report
Optional array key is not recongized when using
!empty
, only works withisset
.Code snippet that reproduces the problem
https://phpstan.org/r/896f13be-9ac0-43bd-9940-d53fbdb6e4be
Expected output
Expected no error.
The text was updated successfully, but these errors were encountered: