父类的静态方法的规范@return
类型是什么,它返回一个子类的实例,在编写时未确定?例如:
<?php
class Thing {
/**
* Do something
*
* @return ??? Instance of some new class.
*/
public static function create_subclass($class) {
return new $class();
}
}
class Person extends Thing {}
$person = Thing::create_subclass('Person');
?>
似乎这不应该是@return self
,因为它返回了self
的子类,并且指定所有可能的返回类将是愚蠢的。有什么想法吗?
答案 0 :(得分:0)
您可以使用@return Thing
或@return Person|AnotherClass|AnotherClass