Search code examples
phpnetbeansautocompletenetbeans-8fat-free-framework

Netbeans 8.2 PHP autocomplete for objects stored in variables inherited from parent class does not work


Good day!

I have question about code auto completion in Netbeans PHP 8.2 X64, running on Windows 10. I have a class which is to be extended:

class Controller {

    protected $obj;

    public function __construct() {
        /* @var obj DataValidator */
        $this->obj = DataValidator::instance();
    }

}

If I extend the class in the same file, autocomplete works for $this->obj.

class BazController extends Controller{
    public function __construct() {
        parent::__construct();
    }

    public function doSomething(){
        $this->obj->doSomething() //autocomplete works!
    }
}

Screenshot - its working!

If I create a new file, it does not work. Netbeans knows the $this->obj, but does not show not the methods $this->obj.

class BarController extends Controller{

    public function __construct() {
        parent::__construct();
    }

    public function doSomething(){
        /* @var this->obj DataValidator */
        $this->obj-> // autocomplete does not work
    }

}

Not working

I would really like to use autocomplete and it works most of the time, but not when doing this. Perhaps other people solved this already (and I was not able to find it?)

Thank you in advance.


Solution

  • Found the solution by myself. You need to add the following to your file to make it work:

    @propery CLASS $varname
    

    So it looks like this:

    <?php
    
    /**
     * Description of FooController
     *
     * @property \DataValidator $dv
     * @property \Base $f3
     * @property \SQL $db
     */
    
    class BazController extends Controller{
    
        public function __construct() {
            parent::__construct();
        }
    
        public function doSomething(){
            /** @var $dv \DataValidator */
            $this->f3->
        }
    
    }
    

    Then, the autocompletion for $this-> will work, as shown in the picture below: Working now..