And*_*och 4 php phpdoc type-hinting phpstorm php-7
我正在使用PhpStorm 10.0.2 开发PHP 7项目。
每当我@param为具有标量类型 ( string, int, ...)类型提示的函数参数声明 PHPDoc 时,我都会收到以下警告:
参数类型不匹配
以下是 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;
}
}
Run Code Online (Sandbox Code Playgroud)
并且 PhpStorm 的屏幕截图在 PHPDoc 中显示有问题的“参数类型不匹配”-提示,用于具有两个强类型字符串参数的构造函数:
有谁知道我是否做错了什么,或者这是否只是 PhpStorm 中的一个错误?
您的 PHPStorm 版本仅在 PHP 7 发布 7 天后发布,因此它对该语言的新功能(包括标量类型提示)的支持不是很好。您遇到了 IDE 错误。您的问题可能是PHPStorm 10.0.3修复的问题
| 归档时间: |
|
| 查看次数: |
1867 次 |
| 最近记录: |