Class-Variable injection
Hey,
In short: Why does this work:
/* @var ArbitraryClassName $wonderfulVariableName */
$wonderfulVariableName = $this->classVariable;
But this won't?
/* @var ArbitraryClassName $this->classVariable */
$this->classVariable = $externalObject; // externalObject is of type ArbitraryClassName
Both in case of trying to get autocomplete with:
$this->[autocomplete] or $wonderfulVariableName->[autocomplete]
The object of $this->classVariable can change and as such a declaration at the top won't be sufficient.
A plugin-name, which adds this functionality to PHPStorm would be great too, if there're no settings or syntax for this.
Thank you very much :),
Torsten
Please sign in to leave a comment.
Hi there,
>In short: Why does this work:
>But this won't?
Because .. PHPDoc does not work this way -- you can type hint only "direct" elements
If you need to type hint $this->classVariable .. then do it inside the actual class where it is declared: https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#722-var
or via @property at PHPDoc comment for the class: https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#714-property