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?
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.