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

标签 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);
}

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

最佳答案

The doc says :

Note that the $paramname,... will be shown in the output docs in both the parameter listing AND the function signature. If you are not indicating in the actual code that the parameter is optional (via "$paramname = 'a default value'"), then you should mention in the parameter's description that the parameter is optional.

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

关于设置可选参数默认值的 phpdoc 标准?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1386913/

相关文章:

php - @return 标记是否对返回类型声明无用

PHP如何检测变量的变化?

php - 传播异常的异常注释

api - 如何生成 Magento 的 API 文档/文档?

php - phpDoc @method 签名中的可选参数

Eclipse 中或外部的 PHPDoc 文档生成器?

php - 从当前日期获取接下来 15 天的数据

php - 刷新 div 从数据库检索信息而不刷新整个页面

php - "Warning: PDO::prepare() expects parameter 2 to be array, string given"- 当仅指定一个参数时

PHP 到 XML foreach 从 mySQL