How to document an array with subarrays (mixed type)?

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'); 

Document a variable that can take an array that receives a vector whose values ​​are integers:

 /* * @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 a document of such an array:

 $foo = array( array('value A', 1, $this), array('value b', 2, NULL), array('value X', 15, new Test) ); 

I imagine something like this:

 /* * @var array[][string|int|object|null] Description. */ 
+5
source share
1 answer

According to the current PHPDoc project (FIG Applicant PSR-5), the @var tag is deprecated . Instead, they suggest using the @type tag .

The type of the variable is still an array; the contents of this array will be briefly mentioned in the description.

 /** * @var array $foo An array of string elements. */ 

or

 /** * @type array $foo An array of string elements. */ 

If a variable can contain things other than strings, I can say An array of mixed elements. , or if I knew for sure that they could be An array of bool|string|object elements.

If the variable itself can be of different types, I would provide a list of types that can be.

 /** * @type bool|string|array $foo Mixed type, depending on result of baz(). */ 
+4
source

Source: https://habr.com/ru/post/1201779/


All Articles