Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to display a multi-line @param using PHPDoc?

From what I've done research on, I can't seem to find a correct method to format a multiline phpdoc @param line. What is the recommended way to do so?

Here's an example:

/**  * Prints 'Hello World'.  *  * Prints out 'Hello World' directly to the output.  * Can be used to render examples of PHPDoc.  *  * @param string $noun Optional. Sends a greeting to a given noun instead.  *                     Input is converted to lowercase and capitalized.  * @param bool   $surprise Optional. Adds an exclamation mark after the string.  */ function helloYou( $noun = 'World', $surprise = false ) {      $string = 'Hello ' . ucwords( strtolower( $string ) );      if( !!$surprise ) {         $string .= '!';     }      echo $string;  } 

Would that be correct, or would you not add indentation, or would you just keep everything on one, long line?

like image 512
Sean Avatar asked Mar 21 '14 14:03

Sean


People also ask

What does @param mean in PHP?

The @param tag is used to document a single argument of a function or method.

What is@ param PHP?

@param doesn't have special meaning in PHP, it's typically used within a comment to write up documentation. The example you've provided shows just that.


1 Answers

You can simply do it this way :

 /**  *  * @param string $string Optional. Sends a greeting to a given noun instead.  *                       Input is converted to lowercase and capitalized.  * @param bool $surprise  */ function helloYou( $string = 'World', $surprise = false ) {     $string = 'Hello ' . ucwords( strtolower( $string ) );      if( !!$surprise ) {         $string .= '!';     }      echo $string; } 

So your example is fine except for one thing : the PHPDoc @param needs to have the same name as the PHP parameter. You called it $noun in the doc and $string in the actual code.

like image 141
Dany Caissy Avatar answered Sep 24 '22 17:09

Dany Caissy