我不明白为什么 PhpStorm 对此方法给出以下警告 PHPDoc comment does not match function or method signature
:
/**
* Create a new instance of the class
* @param string $classname Class to instantiate
* @return object the instance
* @throw FactoryException If the class is not instantiable
*/
private function newInstance($classname) {
$reflectionClass = new \ReflectionClass($classname);
if (! $reflectionClass->isInstantiable()) {
throw new FactoryException("The class $classname is not instantiable.");
}
return new $classname;
}
警告不是很具体,我尝试了几种方法,例如将返回类型更改为“Object”、“mixed”甚至“int”(尝试),但它没有改变。这里有什么问题?
最佳答案
应该是@throws
而不是@throw
。
如果您只需在函数或类变量声明行上输入 /**
,它会自动为您插入一个基本 PHPDoc。这就是我注意到差异的方式。
关于php - 为什么我在 PhpStorm 中收到关于此代码的 PHPDoc 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9823085/