Search code examples
phpphpstormphpdoc

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?


Solution

  • 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…