Netbeans – Introduce a variable

NetBeans is very smart when it scans for variable types. It utilizes comments, specially PHPDoc. Variable types is very useful when the IDE displays code completion. But sometimes when you are working on many files many IDEs and code editors doesn’t identify this variable types so the user will miss the code completion feature of the IDE, which saves a lot of time while coding. To retrieve code completion feature again. You can tell NetBeans about the variable type yourself using the following method.

/* @var $variable VariableType */

This will tell NetBeans about the variable you are using and if it is an instance of some class NetBeans will show code completion when required. This can be great if you are using a PHP framework that uses MVC pattern. Personally I use this technique to acquire code completion for CakePHP helpers,

/* @var $html HtmlHelper */
/* @var $javascript JavascriptHelper */
/* @var $form FormHelper */

Leave a Reply

Your email address will not be published. Required fields are marked *

*