-
-
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
Strict comparison using !== between xxx|void and null will always evaluate to true. #9388
Comments
This is the correct code: https://phpstan.org/r/891c379d-38f9-4493-ab0a-f22783aec94a |
Thank you, you are right with the native type, but how to allow passing Closure that can return nothing - https://phpstan.org/r/c67377cf-3b08-4f29-88de-5fdae8a1c157? |
The easiest way to pass your code: https://phpstan.org/r/0899c462-60f4-400e-bc7d-ea30298182ef |
Please see https://phpstan.org/r/560235d6-759e-45e7-a432-0baf3f09d5a2 and https://3v4l.org/TnQTX . The php code is valid, phpstan is simply wrong here when the type is unioned. See this issue description for possible fix. |
@ondrejmirtes let say that two types are comming from a local/global aliases - https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases and unioned. Then this has to be a bug, when unioned type is assigned and there are 2+ Closures with mixed void/non-void return, the voided one must be casted to null as php does natively. |
@ondrejmirtes I would be happy if this issue can be reopened as unioning any 2 Closures should be valid. |
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
Code snippet that reproduces the problem
https://phpstan.org/r/e8b73d6d-a543-48d1-a67c-dd6a4b6036d1
Expected output
no phpstan error, the condition is clearly not always true, as
void
returns natively/implicitlynull
when Closure result is assigned, check for
void
- https://phpstan.org/r/bc2bb528-17b2-4976-81f2-6187b60e3e14 - is correct, but ifvoid
is part of an union,void
should be converted tonull
internally probablyThe text was updated successfully, but these errors were encountered: