How to hint array of objects with phpdoc?

Hi,
is there a way to document an array of objects of a certain class?

e.g. @param $foo Someclass[] Array of objects of type Someclass

I tried various things but couldn't get anything definitive working and somehow phpdoc itself seems sparse on it too.

thx

3 comments

You must use correct order of elements:

/**
* @param SomeClass[] $foo Bla-bla-description
*/
public function sayWhat ($foo) {
...

0

Thanks, this works. And now I've the next problem. I'm providing a magic __call() and thus don't have documentation und must use @method . I'm failing to understand how can provide hinting for array of classes as a parameter for a magic method. The following does not work for me:

/**
* @method Foo[] bar() bar(Foo[] $bla)
*/
class Foo {
  public function __call() {
    # ...
  }
}

$f = new Foo;
$f->bar..


I get a red underwaved marker here:

* @method Foo[] bar() bar(Foo[] $bla)
                              ^
                              |
marker placed here------------+


The marker says: "Expected: variable"

0

TBH -- I do not know.

I suggest just using normal array there -- should be no difference when using for code completion.

In any case: feel free to submit new ticket to the Issue Tracker describing your issue -- devs will tell for sure if this is an expected behaviour or it is a bug.

0

Please sign in to leave a comment.