如何使用 phpDocumentor 记录 PHP 5 中的类属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2194822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to document class properties in PHP 5 with phpDocumentor
提问by AlexV
Take in consideration the following PHP 5 class:
考虑以下 PHP 5 类:
class SomeClass
{
//I want to document this property...
private $foo;
function __construct()
{
}
public function SetFoo($value)
{
$this->foo = $value;
}
public function GetFoo()
{
return $this->foo;
}
}
How in phpDocumentorwill I document the $foo property? I'm not even sure it need to be documented but I would like to know how if if needs to...
我将如何在phpDocumentor 中记录 $foo 属性?我什至不确定它是否需要记录,但我想知道如果需要...
I know how to document SetFoo() and GetFoo(), I'm just not sure about the private property (variable?).
我知道如何记录 SetFoo() 和 GetFoo(),我只是不确定私有属性(变量?)。
Thanks!
谢谢!
回答by Billy ONeal
/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private $foo;
回答by Pascal MARTIN
I would generally use at least the @vartag, to indicate the type of variable this is.
我通常至少会使用@var标签来指示这是变量的类型。
For instance :
例如 :
/**
* Some blah blah about what this is useful for
* @var MyClass $foo
*/
This is exactly what's done by Zend Framework, for instance ; see Zend_Layout(quoting):
例如,这正是 Zend Framework 所做的;见(引用):Zend_Layout
class Zend_Layout
{
/**
* Placeholder container for layout variables
* @var Zend_View_Helper_Placeholder_Container
*/
protected $_container;
/**
* Key used to store content from 'default' named response segment
* @var string
*/
protected $_contentKey = 'content';
Note : the @accesstag was useful with PHP 4 (when there were no public/protected/private), but I never use it when I document code written in PHP 5 : the code, using the visibility keywords is self-documenting.
注:该@access标签是用PHP 4有用的(当没有public/ protected/ private),但我从来没有使用它,当我记录写在PHP 5代码:代码,使用可视性关键字是自记录文件。
回答by David
In the case you use a __get and __set magic methods you can use @property
如果您使用 __get 和 __set 魔术方法,您可以使用 @property
/**
* Description for the class
* @property type $foo Description for foo
* @property type $foo Description for bar
*/
class SomeClass
{
private $foo;
protected $bar;
public function __get(){
...
}
public function __set(){
...
}
}
Links with more info:
包含更多信息的链接:
回答by Alexander Chzhen
/**
* docstring
*/
private $foo;
Important note: there should be twoasterisks. Not one.
重要提示:应该有两个星号。不是一个。

