How to create PHPDoc for magic properties outside the class definition?

PHPDoc provides an @var tag that should work even for variables declared outside the class.

However, this does not work if I define the variable as the magic element of the object:

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

Where $app is a Slim object that supports arbitrary property assignment using magicians and getters.

I know that I could add it to Slim through the @property tag, but then I will need to change the main Slim code every time I create a new property.

Does PHPDoc support such dynamic property documentation?

+7
php phpdoc slim
source share
1 answer

You do not 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 .

-one
source share

All Articles