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

时间:2022-03-27 11:01:40

Example:

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

The optional parameter is set to true by default. I wish to indicate what the default setting is in the documentation. Is there a standard way of doing this or do I have to mention it in the description?

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

1 个解决方案

#1


13  

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.

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

So if you're not showing the default assignment in the function signature, it would be a good idea to include it in the description, but in your case you are including it in the signature. So, you don't need to change a thing unless doing so would make you feel better.

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

#1


13  

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.

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

So if you're not showing the default assignment in the function signature, it would be a good idea to include it in the description, but in your case you are including it in the signature. So, you don't need to change a thing unless doing so would make you feel better.

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