如何告诉phpDoc一个字符串是一个类名?
我经常为对象提供不需要初始化对象的静态方法和属性。例如:
class SomeObject {
public function __construct($object_id) {
$this->loadProperties($object_id);
}
public static function getSomeStaticString() {
return "some static string";
}
}
现在,我们对这些对象进行子类化,并具有某种控制器,该控制器在对象尚未初始化的某些情况下返回对象类字符串。例如:
class SomeObjectController {
public function getSomeObjectWithTheseProperties(array $properties) {
if($properties[0] === "somevalue") {
if($properties[1] === "someothervalue") {
return SomeSubclassObject::class;
}
return SomeObject::class;
}
return NULL;
}
}
有时,我可能想要在不实际初始化对象的情况下调用静态函数(因为这会涉及不需要的数据库提取)。例如:SomeObject::getSomeStaticString()
$controller = new SomeObjectController;
$properties = array("somevalue", "someothervalue");
$object_class = $controller->getSomeObjectWithTheseProperties($properties);
echo $object_class::getSomeStaticString();
问题:我能以某种方式告诉PhpStorm,最好是通过phpDoc,$object_class
是SomeObject
的子类的类字符串吗?
如果我告诉我的IDE它是一个字符串,它会通知我是一个无效的方法。另一方面,如果我告诉我的IDE它是SomeObject的一个实例,它认为我可以访问常规的非静态方法和属性,而我不能。getSomeStaticString()