PHPStorm - 使用数组进行类型提示

标签 php arrays phpstorm type-hinting

您可以像这样输入提示数组:

/** @var Class[] $variable */
$variable = /*someArrayWithObjects*/;

但是否有可能以不同的方式键入提示数组本身数组的对象?像这样的东西:

/** @var Class, SomeOtherClass[] $variable */
$variable = /*someArrayWithObjects*/;

以便数组本身显示来自 Class 的方法,并且数组的每个对象都显示来自 SomeOtherClass 的方法?

最佳答案

是的。您可以指定 $variable是,例如,CollectionSomeOtherClass 的数组:

/** @var Collection|SomeOtherClass[] $variable */
$variable = /*someArrayWithObjects*/;

这将为您提供 Collection 的代码补全在 $variable以及 SomeOtherClass 中的方法当您遍历 $variable 中的项目时.这当然假设您可以遍历 $variable .

关于PHPStorm - 使用数组进行类型提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28252845/

相关文章:

javascript - 使用 Django 1.8.1 中的 View 列表作为 javascript 模板中的数组

php - 显示实时

php - 根据路由组在错误页面中加载页脚

javascript - 在 node.js 中将数组传递给 jade 模板时出现问题

java - 显示数组问题可能是由于空格字符造成的

javascript - 如何定义单独的本地和远程变量(PHPStorm、Webstorm)

Phpstorm - phpDoc 检查 - 如何强制参数类型声明?

php - 将秒转换为带小数点后两位的时间

php - 将数据拆分为两个表

xdebug - 使用XDebug和PHPStorm进行远程调试