-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
::class
syntax equivalence with instanceof
#9542
Comments
This bug report is missing a link to reproduction at phpstan.org/try. It will most likely be closed after manual review. |
A minimal reproducer, that can then act as regression test too, would be great :) |
Updated the initial message with: https://phpstan.org/r/823b3c7f-6e94-4f71-8a74-3d02c427f4b2 |
Isn't this a logic error in your early exit condition? E.g. looks like the following works fine: https://phpstan.org/r/0c84ecb2-1b23-42a8-9161-a32f7096c5b8 with the or the alternative without the reversed logic / early exit: https://phpstan.org/r/0a5e065c-1fec-4ac4-95eb-580fa0524b0f |
Right, sorry for the mistake i did trying to simplify the code. Here is a reproducer: https://phpstan.org/r/0c84ecb2-1b23-42a8-9161-a32f7096c5b8 Another example using custom classes: https://phpstan.org/r/05f9613a-d9cf-4321-986e-247723efcbb9 The issue come from the order of the condition. |
Yeah, this is easy to fix, TypeSpecifier just handles the condition on one side, we need to handle the inversed variant (yoda condition) too. |
fixed: phpstan/phpstan-src#2498 |
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
PHPStan is able to recognize a condition using
instanceof
syntax (eg:if ($foo instanceof Bar)
), but not a condition using the::class
syntax (eg:if ($foo::class === Bar::class)
) to determine the object class.This result in that break in EasyAdmin project: https://github.com/EasyCorp/EasyAdminBundle/pull/5813/files#r1247414831
Code snippet that reproduces the problem
https://phpstan.org/r/0c84ecb2-1b23-42a8-9161-a32f7096c5b8
https://phpstan.org/r/05f9613a-d9cf-4321-986e-247723efcbb9
Expected output
if ($foo instanceof Bar)
should be equivalent toif ($foo::class === Bar::class)
Did PHPStan help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: