You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a decorator that accepts a class name and uses a static create method and I can't get it to pass phpstan analysis. I've reduced down what I'm trying to do in the given example, and it seems to work fine if I call the constructor directly, but fails when I call the static method.
It doesn't make much sense to reference class-level @template above a static method. Because you're not calling Decorator<Foo>::create($class), you're just calling Decorator::create($class) and the T is unknown.
Thank you for such a prompt reply and a solution to my problem! ❤️
It's confusing to me that a constructor works with the class-level template type but not a static method - I appreciate a constructor's not static, but they're both called without an instance and return an instance (with phpstan inferring the type from the argument). Perhaps generics in other languages are muddying the waters for me slightly, eg. you'd use the same template parameter for the constructor and a static method in C++ IIUC.
It seems the takeaway is that with phpstan a class-level template only covers an instance of the class, rather than the class as a whole.
Thanks again, wasn't expecting a reply on the weekend, hope you get an opportunity to relax!
Bug report
I have a decorator that accepts a class name and uses a static create method and I can't get it to pass phpstan analysis. I've reduced down what I'm trying to do in the given example, and it seems to work fine if I call the constructor directly, but fails when I call the static method.
Code snippet that reproduces the problem
https://phpstan.org/r/092a3bd0-089a-48e0-944a-dcfd4f341583
Expected output
I'd expect it to pass analysis without any errors, but
A::getDecoratorFail()
fails withDid PHPStan help you today? Did it make you happy in any way?
It helped me today, and yesterday, and will help me tomorrow, thank you (:
The text was updated successfully, but these errors were encountered: