38

Take in consideration the following PHP 5 class:

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 phpDocumentor will 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...

I know how to document SetFoo() and GetFoo(), I'm just not sure about the private property (variable?).

Thanks!

4 Answers 4

55
/**
 * This is what the variable does. The var line contains the type stored in this variable.
 * @var string
 */
private $foo;
Sign up to request clarification or add additional context in comments.

Comments

19

I would generally use at least the @var tag, to indicate the type of variable this is.

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) :

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 @access tag 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.

6 Comments

@var MyClass $foo should actually be @property MyClass $foo, based on how you used it (and in that case, @property suggests a magic var). The Zend example that you posted does show proper usage of @var
Thanks for the detail about @access. Thats exctly what I was looking for when I found this page.
+1 -- but should the name of the variable be in the comment in your first example?
the docblock that comes before a variable is the one that documents that variable ; so I would say that the variable's name is implicit (but it might be useful to check how this behaves, just to be sure)
Yeah.. I don't have PHPDocumentor available to test with right now; but I do point out that your second example from Zend Frameowkr doesn't have the names...
|
8

In the case you use a __get and __set magic methods you can use @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:

2 Comments

@property is used to tag magic properties. To mark class members, use @var. See manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/…
In your example, $foo and $bar are no magic properties, because you declared them.
0
/**
 * docstring
 */
private $foo;

Important note: there should be two asterisks. Not one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.