用于设置可选参数默认值的phpdoc标准?

Kdg*_*Dev 13 php phpdoc

例:

/**
 * This function will determine whether or not one string starts with another string.
 * @param string $haystack <p>The string that needs to be checked.</p>
 * @param string $needle <p>The string that is being checked for.</p>
 * @param boolean $case[optional] <p>Set to false to ignore case(capital or normal characters)</p>
 * @return boolean <p>If the $haystack string does start with the $needle string, the return will be true. False if not.</p>
 */
function endsWith($haystack,$needle,$case=true) {
    if($case){return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);}
    return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
}
Run Code Online (Sandbox Code Playgroud)

可选参数true默认设置为.我想说明文档中的默认设置.有没有标准的方法来做到这一点,还是我必须在描述中提及它?

kar*_*m79 13

医生说:

请注意,$ paramname,...将显示在参数列表和函数签名的输出文档中.如果你没有在实际代码中指出参数是可选的(通过"$ paramname ='默认值'"),那么你应该在参数的描述中提到参数是可选的.

因此,如果您没有在函数签名中显示默认赋值,那么将它包含在说明中是个好主意,但在您的情况下,您将其包含在签名中.所以,除非这样做会让你感觉更好,否则你不需要改变它.