Bug report
Classes instantiated from a class string do not have a generic type. The use case in this case is a typed collection class factory function.
Code snippet that reproduces the problem
https://phpstan.org/r/b8d7d149-be06-42bd-941d-67758ffbd708
/**
* @template T
* @template K of IFoo
* @param T $v
* @param class-string<K> $class
* @return K<T>
*/
function make2($v, string $class)
{
return new $class($v);
}
$obj2 = make2(1, Foo::class); // I want to type Foo<int>
\PHPStan\dumpType($obj2); // Kept generic type "int", but unexpected typed as "IFoo" interface
Expected output
Type as Foo<int> and no error will be printed.
Bug report
Classes instantiated from a class string do not have a generic type. The use case in this case is a typed collection class factory function.
Code snippet that reproduces the problem
https://phpstan.org/r/b8d7d149-be06-42bd-941d-67758ffbd708
Expected output
Type as
Foo<int>and no error will be printed.