2

As I know I can't define array of class as function argument.

Like:

someFunc(someClass[] $some) {}

But I get PhpStorm warning about wrong argument when pass the array of class items. Can someone explain to me this warning?

Example of my code:

public function getContent(Item $item)
{
   ...
}

// $items is items array of class Item
$content = getContent($items)
Ivan Kucher
  • 115
  • 1
  • 5

1 Answers1

3

PhpStorm understands phpDoc tags.

So you can do something like this:

/**
 * @param Item[] $item The item to get the content from.
 */
public function getContent(array $item)
{
   ...
}

But you must use array in code since that's what the type is. But PhpStorm will also understand your phpDoc annotation to provide better hints as you type.

mkasberg
  • 16,022
  • 3
  • 42
  • 46