Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document multiple variable declarations in PHPDoc

I'm using short syntax to define member variables of a class so instead of

private $a;
private $b;
private $c;

I use

private
    $a,
    $b,
    $c;

Now I use PHPDoc to tell the IDE of the type of each member like so:

/** @var classA */
private $a;
/** @var classB */
private $b;
/** @var classC */
private $c;

However this doesn't work with the short syntax:

private
    /** @var classA */
    $a,
    /** @var classB */
    $b,
    /** @var classC */
    $c;

What am I doing wrong?

like image 289
John Avatar asked Sep 29 '14 00:09

John


3 Answers

Not the answer you want to hear, but that you can't do. PHPDoc isn't as smart as you want it to be, though life on earth would be almost impossible without it.

Besides, things normally start to get messy when people stop following PSR conventions, like declaring multiple properties per statement. So, don't reinvent the wheel, if you don't like the generally accepted way – stick with it and you'll get over this soon enough ;)

Srsly…

like image 90
Ian Bytchek Avatar answered Oct 15 '22 13:10

Ian Bytchek


Actually, phpDocumentor 2.x does support the compound declaration, though using one docblock rather than many -- http://phpdoc.org/docs/latest/references/phpdoc/tags/var.html

Note that if you don't get the doc results you expect, it may be a bug (like the one shown here -- phpDoc @var for compound statement isn't displayed correctly).

like image 5
ashnazg Avatar answered Oct 15 '22 15:10

ashnazg


If you're looking at similar types; for example:

/** @var string */
private $stringVariable;

/** @var string */
private $stringVariable2;

/** @var string */
private $anotherVariable;

/** @var string */
private $andMoreStringTypes;

you can ofcourse use /** @var string */ for every rule - but you can also use DocBlock templates, like so:

/**#@+
 * @var string
 */
private $stringVariable;
private $stringVariable2;
private $anotherVariable;
private $andMoreStringTypes;
/**#@-*/
like image 4
Rob Avatar answered Oct 15 '22 15:10

Rob