Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comment associative array in PHP Documentor

I use several associative arrays in my PHP application and I'm using PHP documentor to comment my sources. I never really did specify comments for the arrays in an array, but now I need to do that and don't know how.

$array = array('id' => 'test', 'class' => 'tester', 'options' => array('option1' => 1, 'option2' => 2))

How do I comment this array in the correct way for @var and @param comments? I could do this like this, but I don't know if this is correct:

@param string $array['id']
@param string $array['class']
@param int $array['options']['option1']

But how to do this for the @var part?

like image 693
Abenil Avatar asked Apr 26 '10 13:04

Abenil


People also ask

How do I get associative array in PHP?

Answer: Use the PHP array_values() function You can use the PHP array_values() function to get all the values of an associative array.

Is $_ POST an associative array?

The $_POST is an associative array of variables. These variables can be passed by using a web form using the post method or it can be an application that sends data by HTTP-Content type in the request.

What is associative array explain with example in PHP?

Associative Array - It refers to an array with strings as an index. Rather than storing element values in a strict linear index order, this stores them in combination with key values. Multiple indices are used to access values in a multidimensional array, which contains one or more arrays.

What does => mean in PHP array?

It means assign the key to $user and the variable to $pass. When you assign an array, you do it like this. $array = array("key" => "value"); It uses the same symbol for processing arrays in foreach statements. The '=>' links the key and the value.


2 Answers

You can't document each key, but you can tell phpDocumentor what type it is.

You could do something like this:

/**  * Form the array like this:  * <code>  * $array = array(  *   'id'      => 'foo',          // the id  *   'class'   => 'myClass',     // the class  * );  *   * </code>  *  * @var array[string]string   */ $array; 
like image 146
Stephen Fuhry Avatar answered Sep 30 '22 07:09

Stephen Fuhry


I would look at the WordPress Inline Documentation Reference for some hints, though it's not currently comprehensive.

Use @param or @var or @property, whichever is appropriate in your context

According to those guidelines, you might document your associative array like this:

/**
 * @property array $my_array {
 *     An array of parameters that customize the way the parser works.
 *
 *     @type boolean $ignore_whitespace Whether to gobble up whitespace. Default true.
 *     @type string $error_level What the error reporting level is. Default 'none'.
 *                               Accepts 'none', 'low', 'high'.
 * }
 */
like image 31
Tom Auger Avatar answered Sep 30 '22 09:09

Tom Auger