【问题标题】:phpDocumentor @global and @name questionphpDocumentor @global 和 @name 问题
【发布时间】:2011-01-11 00:36:39
【问题描述】:

我使用phpDocumentor 的第一天到目前为止一切都很好,但是我有一个问题我没有在手册中找到...全局变量的文档。

如果出现以下情况,我将如何记录此代码:

  1. $someGlobalVar 在类的 PHP 文件中不是贴花(甚至可以取消声明)。
  2. $someGlobalVar 声明如下:$someGlobalVar = array();(不像 phpDocumentor 手册中那样使用超全局数组)。

PHP 代码:

class myCustomClass
{
    private $someProperty;

    //I want to document the use of global var in this method
    public function getSomeProperty()
    {
        global $someGlobalVar;

        if (isset($someGlobalVar))
        {
            //...
        }
        else
        {
            //...
        }
    }
}

编辑:我想按照手册所示记录这些全局变量,但我不确定如何/在何处放置 @global 和 @name 标签。

编辑 2: 我最终在声明 getSomeProperty 之前使用了以下 sn-p:

/**
 * Get some property based on the $someGlobalVar global.
 * @global array $someGlobalVar User defined array that bla bla bla.
 * @return mixed Return a result bla bla bla.
 */

我使用 phpDocumentor 语法,以便NetBeans IDE 在源代码中显示内联帮助。在 NetBeans 中似乎一切正常,但我不确定这是否可行……

有人可以确认一下吗?

【问题讨论】:

  • 好吧,会通过不使用全局变量来解决这个问题 :) 但我认为这不是你想要的答案。
  • 呵呵没错,但就我而言,我必须记录所做的事情:)
  • 对于在谷歌上搜索问题的任何人,this thread seems to have a detailed answer.

标签: php global-variables phpdoc


【解决方案1】:

您将记录我认为定义它的变量,例如

/**
 * My var
 * @var array
 */
$someGlobalVar = array();

在记录 API 及其功能时,您无需在类方法中记录它。

我的意见。

【讨论】:

    【解决方案2】:

    由于 $someGlobalVar 是用户定义的,经过一些研究,我认为@uses 是最适合记录此内容的方式:

    @uses $someGlobalVar User defined array that bla bla bla.
    

    来自文档:

    @uses 标签可用于记录 任何元素(全局变量,包括, 页面、类、函数、定义、方法、 变量)

    【讨论】:

      猜你喜欢
      • 2011-09-30
      • 2021-08-25
      • 1970-01-01
      • 2016-04-29
      • 2014-12-27
      • 1970-01-01
      • 2011-05-14
      • 2015-10-25
      • 2023-04-02
      相关资源
      最近更新 更多