Correct way to designate an array data type for phpDocumentor?

Which of the following is the correct way to document the return type of this method for phpDocumentor?

Method 1:

/** * @return array Foo array. */ public function foo() { return array(1, 2, 3); } 

Method 2:

 /** * @return integer[] Foo array. */ public function foo() { return array(1, 2, 3); } 

Also, are there any IDE values โ€‹โ€‹from any method?

Edit:

Both PhpStorm and Netbeans 7.1+ IDEs seem to support the second method.

+6
source share
2 answers

Both methods are technically correct, but this one is considered โ€œbetterโ€ because it is more specific ( int and integer interchangeable):

 @return int[] 

Documented here:

http://www.phpdoc.org/docs/latest/guides/types.html

+11
source

At the time of this writing, these are the accepted phpDocumentor methods (and possibly other PHPDocs ) to denote an array:

  • unspecified , the definition of the contents of the represented array is not given. Example: @return array

  • containing one type , the definition of Type informs the reader of the type of each element of the array. Then only one Type expected as an element for the given array. Example: @return int[]

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

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

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


All Articles