-
|
Hi folks, does anyone of you happen to know if the error in https://phpstan.org/r/2052a2a9-0f12-4726-b7c8-1241a71f53fb can be solved using generics or some other PHPStan method? <?php declare(strict_types = 1);
class User
{
public function getName(): string
{
return 'John';
}
}
class HelloWorld
{
/**
* @template T
* @param class-string<T> $class
* @return T
*/
public function foo(string $class)
{
return new $class();
}
}
class Foo
{
public static function getClass(): string
{
return User::class;
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
canvural
Nov 12, 2021
Replies: 2 comments
-
|
Hi, For this example adding |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
leofeyer
-
|
Nice! Thank you very much @canvural. 🎉 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Hi,
For this example adding
/** @return class-string<User> */to thegetClassworks: https://phpstan.org/r/7250f57e-96dc-4905-85df-eccd245265fd