Generics cannot be combined with value-of
Author: jstoksCreated Jul 25, 2024Updated Sep 30, 2026
Labelsfeature-request
Bug report
I'm attempting to implement a function, as part of a class or not, that accepts a string as an argument that matches the value of a constant. The catch is I'd like to make the class containing the constant a Generic of some base type.
I'm pretty sure this should work based one everything I've read in the documentation and logically the information should be available.
Code snippet that reproduces the problem
https://phpstan.org/r/0ee652c0-a80a-401d-a696-51c90b8a4511
Expected output
The error is that the value-of<TemplateType::CONST_ARRAY> is unresolvable.
Did PHPStan help you today? Did it make you happy in any way?
I've been adding PHPStan to our app for the last week and found around a dozen bugs as I went continued to raise the level. I got to 6 and I think I'm more or less done for now though. Tedious but it feels worth it.
Source: phpstan/phpstan