-
-
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
is_subclass_of
is true only for parent classes, not the same one
#6305
Comments
Looking at https://github.com/phpstan/phpstan-src/blob/7667265bba564eb61711ad52376a6e7823708bda/src/Type/Php/TypeSpecifyingFunctionsDynamicReturnTypeExtension.php I guess the problem is in ImpossibleTypeChecker |
The problem is that PHPStan isn't able to represent "subclass of A but not A". |
But I guess it could be if-elsed out in IsSubclassOfFunctionTypeSpecifyingExtension. |
because @staabm found that further up - https://github.com/phpstan/phpstan-src/blob/7667265bba564eb61711ad52376a6e7823708bda/src/Type/Php/TypeSpecifyingFunctionsDynamicReturnTypeExtension.php#L40 |
https://phpstan.org/r/d16311bf-3c5a-4e70-84d0-6da5cf01efa2 seems quite broken to me |
is_subclass_of is fine I think, but it seems weird to me that $b is considered to be A only in https://phpstan.org/r/045b5d07-ca5c-45c9-8cd1-3665296236b3 |
I think so too |
https://phpstan.org/r/d37934ec-1b06-428a-ad62-bd4b9f54e905 l11 and l17 errors seems wrong to me |
checking a condition which already was checked one layer above is redundant. if you don't find a more complete example, IMO phpstan is correct. |
I agree, but if it is part of a more complex condition, it can be needed. And MUST always result the same output. |
please find a example illustrating your case and open a new issue with it |
Fyi I'm trying to fix this properly, I have something that is working, but need to clean it up and add more tests still |
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
is_subclass_of(new A(), A::class)
is false, phpstan assumes trueCode snippet that reproduces the problem
https://3v4l.org/Z4Yb2
https://phpstan.org/r/b41d286a-72cb-45a7-b48f-5dbedc4dee73
Expected output
Call to function is_subclass_of() with B and 'A' will always evaluate to true.
onlyThe text was updated successfully, but these errors were encountered: