【问题标题】:PHPDocumentor optional argumentsPHPDocumentor 可选参数
【发布时间】:2012-04-07 13:14:57
【问题描述】:

我正在尝试为以下内容编写 phpdocumentor 块:

/**
 * 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 定义给了我

在 daysBetween() 中找不到参数 $holidays,...

我相信我可以通过将方法定义修改为来解决这个问题

public function daysBetween($startDate,$endDate,$holidays=NULL) {

但这感觉很笨拙,我认为我不应该为了记录它而必须更改我的函数定义。有人有其他建议吗?

附:我正在使用 PHPDocumentor2

【问题讨论】:

    标签: php phpdoc


    【解决方案1】:

    你当前的语法

    * @param   DateTime    $holidays,...  Optional series of dates that will be excluded
    

    根据参数标签 [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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-30
      • 2012-01-30
      • 1970-01-01
      相关资源
      最近更新 更多