How can I create a PHPDoc for magic properties outside of the class definition?

1.4k views Asked by At

PHPDoc provides the @var tag, which should work even for variables declared outside of a class.

However, this does not seem to work if I define the variable as a magic member of an object:

/** @var $app->translator \Fortress\MessageTranslator */
$app->translator = new \Fortress\MessageTranslator();

Where $app is a Slim object that supports arbitrary property assignment via magic setters and getters.

I know that I could add it to Slim itself via the @property tag, but then I would need to change the core Slim code every time I create a new property.

Does PHPDoc support this kind of dynamic property documenting?

1

There are 1 answers

0
onerror On

You don't need $app->translator in the doc block. It should look like this:

/** @var \Fortress\MessageTranslator your_possible_comments */

or

/** @type \Fortress\MessageTranslator your_possible_comments */

Link to the documentation.