In Netbeans PHP autocomplete does not always work because the type of a variable is not clear. Below you can read how to hint the type thus allowing for autocomplete to work in Netbeans with PHP as well as it does with Java.

Code completion is one of the big upsides of developing code in an IDE so it is quite frustrating if it does not work properly. For example, in the following PHP function, the type of the object variable is unknown to Netbeans, so auto complete does not work:

public function my_function($object) {
    $object-> // php autocomplete does not work.
}

Getting Auto-Complete to work for PHP method parameter in Netbeans

Since PHP 5 type hinting in the method signature is allowed:

public function my_function(MyClass $object) {
    $object-> // php autocomplete works!
}

Using type hinting autocomplete will work in Netbeans. But what if you do not want do change the behavior of the PHP code at all? After all, declaring the type in the method signature leads to a fatal error if an object of a different type is passed (although your code really should not allow that to happen – and if it does, failing might be a good thing). It is also possible to hint to the type in the PHPdoc comment in Netbeans:

/**
 * @param MyClass $object
 */
public function my_function($object) {
    $object-> // php autocomplete works!
}

Getting Auto-Complete to work for all variables in Netbeans

The above solutions are clean and work well for method parameters. But what if the variable is not a parameter? It is possible to use a comment anywhere in the code and declare the type of a variable there to enable code completion:

public function my_function() {
    /* @var $object MyClass  */
    $object = get_object();        
    $object-> // php autocomplete works!
}

This can also be used directly inside a loop:

public function my_function() {
    foreach($objects as /* @var $object MyClass */ $object) {
        $object-> // php auto-complete works!
    }
}

And there you have it: Netbeans auto complete works as well with PHP objects as it does with Java. I prefer hinting to the type directly in the method signature where possible but choose whichever one you like best.