使用PHPDoc显示多行@param的正确方法是什么?

时间:2014-03-21 14:35:02

标签: php documentation phpdoc

根据我所做的研究,我似乎无法找到格式化多行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;

}

这是正确的,还是你不会添加缩进,或者你只是把所有东西放在一条长线上?

1 个答案:

答案 0 :(得分:23)

你可以这样做:

 /**
 *
 * @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参数同名。你在doc和实际代码中的$ string中称它为$ noun。

相关问题