As the IDE's do not exectue the code, they do not know and need some help form you. I know this works for Eclipse and other IDEs as well: Hint the variable's type.
Netbeans / Phpstorm / PDT / ZendStudio Example
/* @var $mailer MailerInterface */$mailer = $sc->mailer
Code complete starts to work again on $mailer
.
For PDT it's important that:
- The comment starts with one
*
only. - First the variable name, than the hint.
Alternative Comment Variants
As it was subject to a lot of discussion, it can differ between IDEs. However most IDEs support variable hinting for inline code variables in the way above. So depending on the IDE this might be written differently but similar, like here with two asterisks in front:
/** @var $mailer MailerInterface */
PHPDoc compatibility
PHPDoc parsers can have a problem if you mimic the class var doc-comment for inline code as so:
/** @var MailerInterface $mailer */
That documentation is normally used for class variables (@var - Document the data type of a class variable). PHPDoc is then missing the definition of the class variable after the comment which involves a burden for QA.
However some IDEs will offer code completition for simple variables as well when written in PHPDoc clas-variable style. I do not know if that has side-effects for the code-completition of the current class then as a new member might get introduced that actually does not exists.