如何在 PHPDoc 中提及属性?

ome*_*itz 2 php phpdoc

我试图在我的班级的其他评论中的其他地方提及我的班级的属性,即。在该类的方法中。

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

(请搜索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);
Run Code Online (Sandbox Code Playgroud)

如何在 PHPDoc 中提及属性?

ash*_*azg 5

如果您需要$mention在文档块文本中包含 ,通常会使用内联 see {@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;
}
Run Code Online (Sandbox Code Playgroud)

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

请注意,较旧的 phpDocumentor 仅允许 inlink 链接标记{@link url|element description}