-
-
Notifications
You must be signed in to change notification settings - Fork 934
Closed
phpstan/phpstan-src
#1388Labels
Milestone
Description
The intersection type class-string<SomeClass>&literal-string does not create an instance of SomeClass when used with new. Code:
<?php declare(strict_types = 1);
class HelloWorld
{
/** @return class-string<self>&literal-string */
public static function getClass(): string {
return self::class;
}
public function build(): self {
$class = self::getClass();
return new $class();
}
}
https://phpstan.org/r/3da883ab-d288-4ca1-9bea-163046e130e4
12 Method HelloWorld::build() should return HelloWorld but returns object.
I wouldn't normally use such a type, but it seems I will have to, to make Doctrine\ORM\QueryBuilder::from() happy, since it now insists on a literal-string.
Did PHPStan help you today? Did it make you happy in any way?
Every day! ❤ I hope that I can find some time to contribute again when things are less busy for me :)