Custom Suggestion with array of classes?


I have a question about the suggestions.

I have a function, that gets me an array of classes

class test
     public $a
     public function getA()


function getTests()

     return array(
          new test();
          new test();
          new test();


In phpDoc I can define the return value for that function with array.
Is it possible, that I define array[test] and if I do the following

$ret = getTests();
for each ($ret as $r){


I get the suggestion for the class?

1 comment
Comment actions Permalink

Hi there,

Use ClassName[] syntax.

* @return test[]

function getTests() {      return array(           new test(),           new test(),           new test()

Alternatively, you can provide typehint for local variable in foreach cycle:

$ret = getTests();
/** @var $r test */
foreach ($ret as $r)
{      $r->...

Please sign in to leave a comment.