In phpDoc-generated documentation I can cause phpDoc to generate a link to a custom type definition for a given param using
@param CustomType $variablename
and that works great. However, the code I'm currently documenting requires CustomType[] parameters, i.e. an array of said CustomType. I want the documentation to be clear that an array is required, but when I use
@param CustomType[] $variablename
phpDoc no longer recognizes the type, and thus can't link to it's definition. This is pretty important in this case - I'm documenting an API that has some fairly complex types that need to be provided.
I've tried several different syntaxes for this and all either treat the entries as separate variable types or break type recognition in the documentation.
Barring this I'll just note it in the parameter note, but it seems more clear to show the array-ness of the parameter in the type.
EDIT
With phpDocumentor 2 (which merged with DocBlox) the
@param CustomType[] $paramName
syntax works, and as noted in @Styx's answer PhpStorm supports type-hinting with that syntax.
Accepted answer updated appropriately.
NOTE: This answer is a complement to the other answers.
To document an array of objects you can use
@param ClassName[] $classInstance Description
. But be aware that with PHP 7 you can use argument type declarations (type hints) and in this case, the type must bearray
.Example:
TIP: You should also use
declare(strict_types=1);
The best you can do is:
This should help the reader realize the true datatype of $variablename, while indicating the expectation of what the array contains.
This won't be enough to help an IDE's autocompletion when it comes to using a member from $variablename and expecting properties/methods of CustomType to appear. There's really no way to get that behavior currently.
See the following examples from: https://code.google.com/p/google-api-php-client/source/checkout where is described the array structure of input parameters.
New version of PHP doc support
/** @var sometype[] */
syntax. Even more complicated:/** @var (sometype|othertype)[] */
. http://www.phpdoc.org/docs/latest/guides/types.html#arrays PHPStorm also support this syntax.The phpdoc documentation notes at http://www.phpdoc.org/docs/latest/guides/types.html
And... there is no link and no chapter "on arrays". So no, this looks like a forthcoming feature.