如何在PHPDoc中提及属性?

时间:2018-01-19 14:36:17

标签: 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);

如何在PHPDoc中提及属性?

1 个答案:

答案 0 :(得分:2)

如果您需要在docblock文本中使用$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独立标记也可用,但不能将链接嵌入到docblock叙述文本中。

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