我正在使用Visual Studio Code(VS代码),它可以显示functios的注释。 我试图改善写PHPDoc标准。 有什么建议吗?谢谢。
这里有3个功能,但它们不是重点。 我只想知道如何编写PHPDoc标准来描述函数2和模拟重载函数3。
参考: https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#54-examples
<?php
// Function 1:
/**
* Check if A is equal to B.(Just a sample note, not important)
*
* @param string A
* @param string B
*
* @return bool
*/
function checkAandB_1($a, $b){
if($a === $b)
return true;
return false;
}
// Function 2:
/**
* Check if A is equal to B.(Just a sample note, not important)
*
* @param string Input x,y (<=here, I need to known how to write a right note to describe this function can support input a string combin x and y with a comma in one line)
*
* @return bool
*/
function checkAandB_2($str){
if( substr_count($str, ",") === 1 ) {
$strArr = explode(",",$str);
if($strArr[0] === $strArr[1])
return true;
}
return false;
}
// Function 3: Simulation a overload function
/**
* Check if A is equal to B.(Just a sample note, not important)
*
* @param string (What's the best annotation to describe this function?)
*
* @return bool
*/
function checkAandB_overload($str, $b = null){
if(isset($b) && $str === $b){
return true;
}elseif( substr_count($str, ",") === 1 ) {
$strArr = explode(",",$str);
if($strArr[0] === $strArr[1])
return true;
}
return false;
}
var_dump(checkAandB_1("1","2")); // false
var_dump(checkAandB_1("2","2")); // true
var_dump(checkAandB_2("1,2")); // false
var_dump(checkAandB_2("2,2")); // true
var_dump(checkAandB_overload("1","2")); // false
var_dump(checkAandB_overload("2","2")); // true
var_dump(checkAandB_overload("1,2")); // false
var_dump(checkAandB_overload("2,2")); // true