如何在 PHPDoc 中提及 属性?

How to mention a property in PHPDoc?

我想在我的 class 的其他评论中的其他地方提到我的 class 的 属性,即。在 class.

的方法中

例如,如果我们有这样的代码:

(请搜索:property $mention -- @property Village::mention does not work

class Village {
    /**
     * @var array Data container.
     */
    public $data = [];

    /**
      *
      */
    public $mention = 'Me';

    /**
     * Village constructor which injects data.
     *
     * @param $data
     */
    public function __construct($data) {
        $this->data = $data;
    }

    /**
     * A factory for our Villages.
     * 
     * @return Village
     */
    public static function hillbilly() {
        return new Village;
    }

    /**
     * Name tells the story...
     *
     * Now somewhere at this exact point I want to mention the
     * $mention property -- @property Village::mention does not work
     * nor does @property $mention either...
     *
     * @return array Rednecks unset.
     */
    public function redneck() {
        if(sizeof($data)) {
            unset($data);
        }

        return $data;
    }
}

$countryside = [
    'important' => 'data',
    'axe' => 'knifes',
    'shovel' => 'hoe',
    'trowel' => 'mixer',
];

$village = Village::hillbilly($countryside);

如何在 PHPDoc 中提及 属性?

如果您需要在文档块文本中包含 $mention,通常会使用内联,请参阅 {@see element description}:

/**
 * Name tells the story...
 *
 * Now somewhere at this exact point I want to mention the
 * {@see Village::$mention} property.
 *
 * @return array Rednecks unset.
 * @see Village::$mention
 * @uses Village::$mention
 */
public function redneck() {
    if(sizeof($data)) {
        unset($data);
    }

    return $data;
}

@see@uses 独立标签也可用,但不能将 link 嵌入到文档块叙述文本中。

请注意,较旧的 phpDocumentor 只允许 inlink link 标签 {@link url|element description}.