How to document an array from [type]?

Say I have a function like this:

function theFunction() { $arr = array(); for ($i=0;$i<10;$i++) { $arr[] = new theObject($i); } return $arr; } 

I need to document the return type of a function. I could, of course, use array , but this does not provide all the information that can be provided, and does not tell the developer about the true nature of the function.

How do I document the type "array" [type] "in PHPDoc?

+7
source share
3 answers

From phpDocumentor documentation

The value represented by the type can be an array. The type MUST be specified after the format of one of the following options:

  • undefined , the definition of the contents of the presented array is not defined. Example: @return array

  • containing one type , the type definition informs the reader about the type of each element of the array. Then, only one type is expected as an element for this array.

    Example: @return int[]

    Note that mixed is also one type and with this keyword you can indicate that each element of the array contains any possible type.

  • containing several types , the type definition informs the reader about the type of each element of the array. Each element can be any of the given types. Example: @return (int|string)[]

    Note
    many IDEs probably do not yet support this notation.

+9
source

If I remember correctly, you indicate the type of return and description, can you indicate it in the description?

 /** * blah * @return array array of types */ 
+1
source

In PHPDoc, you can do the following for members of an array of type hinting:

 @var array<\My\Folder\ClassName> 
0
source

All Articles