0

Let's say that I have a function that returns array $data with a User object $user and a Car object $car

function my_function(){
    return array(
        new User(),
        new Car()
    );
}

What should I use for my @return parameter for the function documentation?

1 Answer 1

1

I Would do it this way

/**
 * @return User[]|Car[]
 */

General | means or and SomeType[] means there is an array of SomeType

Are you Sure, you did not want this?

/**
 * My Parent Object
 */
class SomeClass {

    /**
     * The User
     * @var User
     */
    public $User;

    /**
     * The Car
     * @var Car
     */
    public $Car;
}

The good (evil) thing about PHP is, you can mix array types. In a strong Typed Language (for reason) you can not. Here we use Interfaces and something like this. What we try with PHPDoc is to strong type PHP. So you should play the rules of a strong typed language.

1
  • thanks for you last comment, I'll try to update my code then!
    – syl.fabre
    Commented Aug 30, 2014 at 13:05

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.