考虑以下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;
}
}
Run Code Online (Sandbox Code Playgroud)
如何在phpDocumentor中记录$ foo属性?我甚至不确定它是否需要记录,但我想知道如果需要......
我知道如何记录SetFoo()和GetFoo(),我只是不确定私有属性(变量?).
谢谢!
Bil*_*eal 41
/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private $foo;
Run Code Online (Sandbox Code Playgroud)
Pas*_*TIN 17
我通常至少会使用@var标签来表示变量的类型.
例如 :
/**
* Some blah blah about what this is useful for
* @var MyClass $foo
*/
Run Code Online (Sandbox Code Playgroud)
这正是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';
Run Code Online (Sandbox Code Playgroud)
注意:@access标签对于PHP 4很有用(当没有public/ protected/时private),但是当我记录用PHP 5编写的代码时,我从不使用它:使用visibility关键字的代码是自我记录的.
如果您使用 __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(){
...
}
}
Run Code Online (Sandbox Code Playgroud)
包含更多信息的链接: