I have a problem with @return
types. It seems that either it’s a bug in PHPStan or I’m doing something wrong.
abstract class Aclass {}
final class Bclass extends Aclass {}
final class Cclass extends Aclass {}
final class Factory {
/**
* @template T of Aclass
* @param class-string<T> $param
* @return T
*/
public function create($param) {
// some kind of factory logic
return new Bclass();
}
}
abstract class Aclass {}
final class Bclass extends Aclass {}
final class Cclass extends Aclass {}
final class Factory {
/**
* @template T of Aclass
* @param class-string<T> $param
* @return Aclass
*/
public function create($param) {
// some kind of factory logic
return new Bclass();
}
}
Why does PHPStan give me an error? Isn’t @template T of Aclass
+ @return T
the same as @return Aclass
?
I’m expecting no errors.