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?
The @param tag is used to document a single argument of a function or method.
@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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With