【发布时间】:2014-08-29 01:00:32
【问题描述】:
是否可以提示 PhpStorm 在下面的代码中 item() 方法的返回值具有 DOMElement 类型(不修改实际的 PHP 语句,即通过 PhpStorm 的一些外部设置或插件或使用某种 PHPDoc 注释等)?
再次,请不要建议我修改代码中的语句,尤其是 $list->item(0)->getAttribute('test') 部分。
另外,我发现了一个有点相似的问题 PhpStorm type-hinting for factories?,但它处理用户定义函数的类型提示,在我的例子中,函数 item() 是一个预定义的库函数。
$doc = new DOMDocument();
$doc->loadXML('<x test="123"/>');
$list = $doc->getElementsByTagName('x');
if($list->length > 0)
var_dump($list->item(0)->getAttribute('test'));
【问题讨论】:
-
只是为了做到这一点:您不能更改上面列出的任何代码?还是不能更改 item(0) 调用的实现?
-
@nivekastoreth 只能更改空格 - 这包括添加作为空格子情况的 cmets。
-
已在 strubs 中修复。 github.com/JetBrains/phpstorm-stubs 外部库 -> PHP 运行时 -> 高级设置 -> 默认 srubs 路径:C:\User\Name\
标签: php phpstorm phpdoc type-hinting