php - 为什么PhpStorm会报 "Argument type does not match"错误?

标签 php phpstorm phpdoc php-7 type-hinting

我正在使用 PhpStorm 10.0.2 开发一个 PHP 7 项目。

每当我为函数参数声明 PHPDoc @param 时,该参数具有标量类型的类型提示(stringint、.. .) 我收到这个警告:

Argument type does not match

这是 PhpStorm 提示的一些示例代码:

class HostConfig
{
    /**
     * @var string
     */
    private $hostname;
    /**
     * @var string
     */
    private $domainname;

    /**
     * Creates a new instance of hte HostConfig model.
     *
     * @param string $hostname   A host name (e.g. "dev", "int", "feature-xy")
     * @param string $domainname A domain name (e.g. "example.com")
     *
     * @throws \InvalidArgumentException If the given $hostname is empty
     * @throws \InvalidArgumentException If the given $domainname is empty
     */
    public function __construct(string $hostname, string $domainname)
    {
        if (strlen(trim($hostname)) === 0) {
            throw new \InvalidArgumentException("The host name cannot be empty");
        }

        if (strlen(trim($domainname)) === 0) {
            throw new \InvalidArgumentException("The domain name cannot be empty");
        }

        $this->hostname = $hostname;
        $this->domainname = $domainname;
    }
}

PhpStorm 的屏幕截图显示有问题的“参数类型不匹配”- 在 PHPDoc 中提示具有两个强类型字符串参数的构造函数:

Screenshot of PhpStorm displaying an "Argument type does not match" hint for a string function parameter that has type hinting

有人知道我是做错了什么还是这只是 PhpStorm 中的一个错误?

最佳答案

您的 PHPStorm 版本仅在 PHP 7 发布 7 天后发布,因此它对该语言的新功能(包括标量类型提示)的支持不是很好。您遇到了 IDE 错误。您的问题是 probably this onePHPStorm 10.0.3 固定

关于php - 为什么PhpStorm会报 "Argument type does not match"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38473264/

相关文章:

php - 使用较低的 MySQL 方法 POST?

phpstorm - 更改 PHPStorm 中相似单词的颜色

PHPStorm 和魔术方法

php - 在 Javascript 中解析一个单独的 PHP 数组

php - phalcon 获取枚举值

android-studio - 合并 Intellij IDE 以仅安装一个

phpDocumentor - 更改模板

codeigniter - 使用 codeigniter 在 mvc 项目上使用 phpdoc

javascript - 服务器上出现意外的 T_STRING 错误,但本地主机上没有

php - 有没有办法让 PhpStorm 的自动完成 "go deeper"?