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

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 FortressMessageTranslator */
$app->translator = new FortressMessageTranslator();

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?


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

/** @var FortressMessageTranslator your_possible_comments */

or

/** @type FortressMessageTranslator your_possible_comments */

Link to the documentation.

链接地址: http://www.djcxy.com/p/58626.html

上一篇: PhpStorm对象属性类型提示

下一篇: 我怎样才能创建一个PHPDoc魔术属性的类定义之外?