To document a variable that can take an array that receives a vector whose values are strings:
/*
* @var string[] An array of string objects.
*/
$foo = array('A', 'B', 'C');
To document a variable that can take an array that receives a vector whose values are integer:
/*
* @var int[] An array of string objects.
*/
$foo = array(1, 5, 0);
how should I document a variable whose values are mixed arrays?
I need document a array like this:
$foo = array(
array('value A', 1, $this),
array('value b', 2, NULL),
array('value X', 15, new Test)
);
I imagine it's something like this:
/*
* @var array[][string|int|object|null] Description.
*/
According to the current draft of PHPDoc (FIG PSR-5 applicant), the @var tag is deprecated. They suggest using an @type tag instead.
The type of variable is still an array; the contents of that array would be be briefly mentioned in the description.
/**
* @var array $foo An array of string elements.
*/
or
/**
* @type array $foo An array of string elements.
*/
If the variable might contain things other than strings, I might say An array of mixed elements.
, or if I knew specifically what they might be An array of bool|string|object elements.
If the variable itself might be of various types, I would give the list of types it might be.
/**
* @type bool|string|array $foo Mixed type, depending on result of baz().
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With