10

Which of the following is the proper 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 implications from either method?

Edit:

It appears that both PhpStorm and Netbeans 7.1+ IDEs support the 2nd method.

2 Answers 2

18

Both methods are technically correct, but this one is considered 'better' because it's more specific (int and integer are interchangeable):

@return int[]

Documented here:

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the link! I can't believe I missed this. I want to mark this as the correct answer, except that section 1.4.4 states that either syntax I listed is correct, where your answer specifies only the second is correct (though the 2nd is definitely the most helpful, IMHO).
Both are correct, but this one considered 'better' because it's more specific. int/integer are interchangable though.
@drrcknlsn: I appreciate the fact that you took the time to do the edit.
8

At the moment of writing this answer, these are the accepted ways of phpDocumentor (and probably other PHPDoc implementations) to denote an array:

  1. unspecified, no definition of the contents of the represented array is given. Example: @return array

  2. specified containing a single type, the Type definition informs the reader of the type of each array element. Only one Type is then expected as element for a given array. Example: @return int[]

    Please note that mixed is also a single type and with this keyword it is possible to indicate that each array element contains any possible type.

  3. specified containing multiple types, the Type definition informs the reader of the type of each array element. Each element can be of any of the given types. Example: @return (int|string)[]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.