为什么我会在 PhpStorm 中通过此代码收到 PHPDoc 警告 [英] Why do I get a PHPDoc warning in PhpStorm over this code

查看:46
本文介绍了为什么我会在 PhpStorm 中通过此代码收到 PHPDoc 警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么 PhpStorm 给我以下警告 PHPDoc 注释与此方法的函数或方法签名不匹配:

I can't understand why PhpStorm gives me the following warning PHPDoc comment does not match function or method signature over this method:

/**
 * 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"(尝试),但没有改变.这里有什么问题?

The warning isn't very specific, I've tried several things like changing the return type to "Object", "mixed" or even "int" (to try) but it didn't change. What is the problem here ?

推荐答案

应该是 @throws 而不是 @throw.

如果您只是在函数或类 var 声明的行上键入 /** ,它会自动为您插入一个基本的 PHPDoc.这就是我注意到差异的方式.

If you just type /** over the line of a function or class var declaration it'll auto insert a base PHPDoc for you. That's how I noticed the difference.

这篇关于为什么我会在 PhpStorm 中通过此代码收到 PHPDoc 警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆