【问题标题】:phpdoc standard for setting default value of an optional parameter?用于设置可选参数默认值的phpdoc标准?
【发布时间】:2010-11-26 02:14:24
【问题描述】:

例子:

/**
 * 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);
}

可选参数默认设置为true。我希望在文档中指出默认设置。是否有执行此操作的标准方法,还是我必须在说明中提及?

【问题讨论】:

    标签: php phpdoc


    【解决方案1】:

    The doc says:

    注意 $paramname,... 将是 显示在两个输出文档中 参数列表和函数 签名。如果您不指示 在参数的实际代码中 是可选的(通过“$paramname = 'a 默认值'"),那么你应该 在参数说明中提及 该参数是可选的。

    因此,如果您没有在函数签名中显示默认分配,最好将其包含在描述中,但在您的情况下,您 将其包含在签名中。所以,你不需要改变任何事情,除非这样做会让你感觉更好。

    【讨论】:

    • 谢谢。它确实让我感觉好多了,是的:)
    • 这是在函数签名中包含可选参数时的答案。但如果不是呢?如何记录可选参数?从文档中唯一的方法是在描述中告诉它。所以没有办法写例如[$case=true]。连jsdoc都有。
    猜你喜欢
    • 2010-11-10
    • 2011-02-13
    • 1970-01-01
    • 2017-01-11
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多