开发者

Can you hint an array's items type? [duplicate]

This question already has answers here: PHPDoc type hinting for array of objects? (14 answers) Closed 8 years ago.

This question is linked to this one :

Is it possible to hint the type of the items inside a returned array ?

e.g. :

/**
 *  MyFunction does a lot of things
 *
 * @param TClass1 $var1
 * @param TClass2 $var2
 * @return array[TClass3] //<- I'm trying to express this
 */
 function MyFunction( $var1, $var2 ){
   ...

I am using NetBeans as an IDE, which takes (like many other PHP IDEs) advantage of the doc blocs above functions to determine the type of returned values.

If I could explain what type is expected inside an array, I could hope for the IDE to be able to offer correct completion for the following case :

  $myTab = MyFunction( $foo, $bar );
  foreach(开发者_如何学编程 $myTab as $itm ){
    $itm->myFi| //offer the completion for a TClass3 object
  }


Use

@return TClass3[]

or

@return TClass3[]|TClass3


Are you trying to hint the return type so the documentation generates it? If so you could probably do it, you could also put it in the description of that variable.

It's a comment, you're allowed to do anything in it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜