Search code examples
phpphpdocphp-7

Is @return tag useless with return type declaration


Is phpdoc's @return tag useless with return type declaration? In other words, is there any benefits in @return tag in this case:

/**
 * Example function.
 *
 * @return int
 */
public function getOne(): int
{
    return 1;
}

Should we remove this annotation in PHP7?


Solution

  • Should we remove this annotation in PHP7?

    While @return may look redundant at first glance, it is not. It allows you to put more detailed description about returned value, its meaning, not only type of the value which may be pretty useless in case of more complex data returned (i.e. arrays), therefore I'd rather put some more efforts to make my docs better by using this feature instead of removing @return for no real benefit.