我正在尝试为以下内容编写 phpdocumentor block :
/**
* daysBetween
*
* Returns the number of whole working days between start_date and end_date. Working
* days exclude weekends and any dates identified in holidays.
* Use NETWORKDAYS to calculate employee benefits that accrue based on the number of
* days worked during a specific term.
*
* @param DateTime $startDate Start date
* @param DateTime $endDate End date
* @param DateTime $holidays,... Optional series of dates that will be excluded
* @return integer Interval between the dates
*/
public function daysBetween($startDate,$endDate) {
// Shift the mandatory start and end date that are referenced
// in the function definition, to get any optional days
$holidays = func_get_args();
array_shift($holidays);
array_shift($holidays);
$startDate 和 $endDate 是强制参数,而 $holidays 的所有实例都是可选的……可能没有定义一个或多个 $holiday 日期。上面的 PHPDocumentor 定义给了我
Parameter $holidays,... could not be found in daysBetween()
我相信我可以通过修改方法定义来解决这个问题
public function daysBetween($startDate,$endDate,$holidays=NULL) {
但这感觉非常笨拙,我认为我不应该为了记录它而必须更改我的函数定义。还有其他建议吗?
附言我正在使用 PHPDocumentor2
最佳答案
你当前的语法
* @param DateTime $holidays,... Optional series of dates that will be excluded
根据 param 标记 [1] 的 phpDocumentor 手册,它看起来是正确的。此页面显示“$holidays,...”语法应该足以让 phpDocumentor 识别未直接出现在代码方法签名中的可选参数。
这个“Parameter $holidays,... could not be found in daysBetween()”响应可能需要在 github 页面 [2] 上打开一个新问题。
[1] -- http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.param.pkg.html
[2] -- https://github.com/phpDocumentor/phpDocumentor2/issues/424
关于PHPDocumentor 可选参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9831390/