Bug report
Traits are analyzed per context, and that context can be very different, and static. If the trait is generic, the parent class can add staticness in per-context analysis, but that's not static for the trait code:
class Class1 {
/** @use PrintSomething<null> */
use PrintSomething;
}
class Class2 {
/** @use PrintSomething<Exception> */
use PrintSomething;
The trait is used for all kinds of contexts, sometimes Exception, sometimes null, sometimes Model, etc.
The trait itself doesn't know which context, so it has to check:
if ($this->model instanceof Exception) {
but per-context, that's a stupid if, because in Class2-context, of course it's an Exception! And in Class1-context, of course it's not an Exception! But the trait itself doesn't know that, so it has to check. And the if check findings from PhpStan are silly:
11 Negated boolean expression is always true.
11 Negated boolean expression is always false.
It's always true AND always false 😮
Code snippet that reproduces the problem
Expected output
0 errors, because PhpStan knows $this->model is variable, not static, because it's a generic filled in by the parent class.
The echo $this->model; is a dumb example, but stuff happens there (if it's not the null context).
Did PHPStan help you today? Did it make you happy in any way?
PhpStan is crazy smart mostly! template-type through array keys of an argument through a Builder!? ❤️ https://phpstan.org/r/6f3bfb6b-7f60-4935-805c-bf377bd6bd32
Bug report
Traits are analyzed per context, and that context can be very different, and static. If the trait is generic, the parent class can add staticness in per-context analysis, but that's not static for the trait code:
The trait is used for all kinds of contexts, sometimes
Exception, sometimesnull, sometimesModel, etc.The trait itself doesn't know which context, so it has to check:
but per-context, that's a stupid
if, because inClass2-context, of course it's anException! And inClass1-context, of course it's not anException! But the trait itself doesn't know that, so it has to check. And theifcheck findings from PhpStan are silly:It's always true AND always false 😮
Code snippet that reproduces the problem
Expected output
0 errors, because PhpStan knows
$this->modelis variable, not static, because it's a generic filled in by the parent class.The
echo $this->model;is a dumb example, but stuff happens there (if it's not thenullcontext).Did PHPStan help you today? Did it make you happy in any way?
PhpStan is crazy smart mostly!
template-typethrough array keys of an argument through a Builder!? ❤️ https://phpstan.org/r/6f3bfb6b-7f60-4935-805c-bf377bd6bd32