PhpStorm 警告“Expected Class, got Class[]”
PhpStorm warns about “Expected Class, got Class[]”
据我所知,我无法将 class 的数组定义为函数参数。
喜欢:
someFunc(someClass[] $some) {}
但是当传递 class 项的数组时,我收到 PhpStorm 关于参数错误的警告。有人可以向我解释这个警告吗?
我的代码示例:
public function getContent(Item $item)
{
...
}
// $items is items array of class Item
$content = getContent($items)
PhpStorm 理解 phpDoc 标签。
所以你可以这样做:
/**
* @param Item[] $item The item to get the content from.
*/
public function getContent(array $item)
{
...
}
但是您必须在代码中使用array
,因为这就是类型。但 PhpStorm 也会理解您的 phpDoc 注释,以便在您键入时提供更好的提示。
据我所知,我无法将 class 的数组定义为函数参数。
喜欢:
someFunc(someClass[] $some) {}
但是当传递 class 项的数组时,我收到 PhpStorm 关于参数错误的警告。有人可以向我解释这个警告吗?
我的代码示例:
public function getContent(Item $item)
{
...
}
// $items is items array of class Item
$content = getContent($items)
PhpStorm 理解 phpDoc 标签。
所以你可以这样做:
/**
* @param Item[] $item The item to get the content from.
*/
public function getContent(array $item)
{
...
}
但是您必须在代码中使用array
,因为这就是类型。但 PhpStorm 也会理解您的 phpDoc 注释,以便在您键入时提供更好的提示。