autocompletion of methods

Hello!

At the moment I am testing different PHP design patterns.
In addition I have written the following classes to the test.


----------------------------------------------
class foo {
    protected $bbb = null;

    public function getBbb()
    {
        $this->ccc();

        return $this->bbb;
    }

    public function setBbb($bbb)
    {
        $this->bbb = $bbb;
    }

    private function ccc()
    {
        $this->bbb .= 'ddd';
    }
}



class indexExtends {

    public function aaa()
    {
        $this->ccc();

        return $this;
    }
    
    public function bbb()
    {
        $this->ccc();

        return $this;
    }

    private function ccc()
    {

    }
}


class index extends indexExtends {

    protected $object = null;

    public function __construct($object)
    {
        $this->object = $object;
    }

   public function ddd()
    {
        // auto complete don't work
        $this->object->setBbb('abc');

        return $this;
    }
}

$foo = new foo();

$test = new index($foo);
$test->ddd();
$test->aaa();

-----------------------------

The class 'index' is extended to the class 'indexExtends'.
In the class 'index' I add the class 'foo' a.

I want to 'index-> ​​ddd ()' with $ this-> object-> setBbb ($ bbb); work.
Unfortunately, the autocompletion does not work.

Who can help?

Sincerely yours

Stephan

1 comment

Hi there,

I want to 'index-> ​​ddd ()' with $ this-> object-> setBbb ($ bbb); work.
Unfortunately, the autocompletion does not work.



Who can help?


You have to tell PhpStorm what $object is (what type)  as IDE cannot take actual type of the $object out of nowhere (PHP itself can, as it will know the type when code will be executed).

For your example, adding single PHPDoc comment (with correct class name) solves it:

    /** @var foo  */
    protected $object = null;

0

Please sign in to leave a comment.