Search code examples
phpphpdoc

PhpDoc: protected property


Is it possible to declare protected or private class @property using PhpDoc?

/**
  * Class Node
  * @package app\models
  * @property string $name
  */
class Node
{

}

Solution

  • I don't think so. For @property, public is implied, even if it's read-only or write-only. The point of such tags is about documenting interfaces that can't be inferred. A private/protected variable is really internal to the class so it's only relevant to child classes which should be written as if they already know this. You can still leave a plain docblock immediately before you declare it, though.