CGriffin
CGriffin

Reputation: 1476

Documentation: how do I document that a function can return more than one type of variable?

Assume a PHP function like this:

/**
 * Description
 *
 * @return  Namespace\GenericObject
 */
function doSomething() {
    if ($some_parameter) {
        return new GenericObject;
    } else {
        return FALSE;
    }
}

How should the return of the function be documented, using PHPDoc standard? As far as I know, a function should only have one return documented, yet, the function above can return either a new object, or a bool.

Upvotes: 1

Views: 48

Answers (1)

bassxzero
bassxzero

Reputation: 5041

Use the or | operator.

/**
 * Description
 *
 * @return  Namespace\GenericObject|null|array|false
 */
function doSomething() {
    if ($some_parameter) {
        return new GenericObject;
    } else {
        return FALSE;
    }
}

Upvotes: 4

Related Questions