gpt4 book ai didi

php - 如何在 PHPDoc 中提及属性?

转载 作者:行者123 更新时间:2023-12-03 09:04:13 25 4
gpt4 key购买 nike

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

例如,如果我们有以下代码:

(请搜索:property $mention -- @property Village::mention 不起作用)

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 中提及属性?

最佳答案

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

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

关于php - 如何在 PHPDoc 中提及属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48343439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com