1

My code review was refused by my co-worker, because of an unnecessary phpdoc on a local array ($params in bottom example) in a function. See the example:

/**
 * comment...
 *
 * @return int
 */
public function testFunction()
{
    /** @var string[] $params */
    $params = ['string1', 'string2'];

    etc...

    return 0;
}

Can someone explain to me why defining phpdocs on local arrays is unnecessary? I got an explanation from my co-worker that we don't need to write phpdocs on local arrays. We are using PhpStorm and Doctrine.

Thanks for your time.

2
  • 3
    "Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise." Commented Apr 3, 2019 at 21:17
  • 1
    This is entirely opinion-based. Many people prefer PHPDoc on all local variables. In this case, I would personally be using PHPDoc, as you have done. Commented Apr 3, 2019 at 22:53

1 Answer 1

1

Writing a phpdoc like string[] for an array is useful when the array is a parameter or a return value, so you can specify what types of values the array should contain. But in that case it's an array of string literals defined right there. The phpdoc isn't telling you anything you can't know just by looking at it.

Technically @var is intended to document class properties, but in some cases it can be useful inside a function to help the IDE when it's unable to determine the type of a variable. That's not really needed here either, though.

I can't know for sure if that's exactly why your co-worker thought it was unnecessary, but I don't see another logical explanation for it.

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

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.