根据我所做的研究,我似乎无法找到一种正确的方法来格式化多行 phpdoc @param
行。推荐的方法是什么?
这是一个例子:
/**
* 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;
}
这是正确的,还是不添加缩进,还是将所有内容都放在一个长行中?
最佳答案
你可以简单地这样做:
/**
*
* @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;
}
所以您的示例很好,除了一件事:PHPDoc @param 需要与 PHP 参数同名。您在文档中称其为 $noun,在实际代码中称其为 $string。
关于php - 使用 PHPDoc 显示多行 @param 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22561684/