gpt4 book ai didi

php - 为什么我在 PhpStorm 中收到关于此代码的 PHPDoc 警告

转载 作者:行者123 更新时间:2023-12-03 00:09:59 25 4
gpt4 key购买 nike

我不明白为什么 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。这就是我注意到差异的方式。

enter image description here

关于php - 为什么我在 PhpStorm 中收到关于此代码的 PHPDoc 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9823085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com