instanceof in a trait is "always true" AND "always false"
PFQNiet opened this issue · 2 comments
Demonstration of the issue: https://phpstan.org/r/b793ec1a-e47e-4f6f-b3d6-0bf9595bb1a2
In my actual use, SomeTrait
has ORM-like behaviour. Classes using it should provide a getId
method that returns the primary key, and internally getRawId
is used to convert object-based IDs into an int|string
for use in the DB.
But Strict Rules doesn't like the check for object-based IDs because, according to the narrower return type of getId
on the classes that use the trait, the instanceof
is always true... but it can also be always false. It depends what type is used by the class (Foo
and Bar
classes in the demo).
Is this an issue with the rule, or my implementation?
Trait is analysed in context of each class that uses it. I recommend you to ignore this error: https://phpstan.org/r/8641beec-6ae4-4dc0-be0b-0ad9829c9886
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.