Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typehint inherited class variables in PHPStorm

Tags:

phpstorm

In PHPStorm, I can type-hint a variable this way:

/** @var Point $point */
$point->x();

However, say I inherited a variable from a parent class, and want to type-hint it:

class PointProxy extends Proxy
{
    public function x()
    {
        ...

        /** @var Point $this->geometry */
        return $this->geometry->x();
    }
}

This doesn't work, PHPStorm acts as if I had type-hinted $this, and not $this->geometry.

Is there a way to make such a type-hint work without redeclaring the $geometry property in the subclass, or is this unsupported?

like image 852
BenMorel Avatar asked Mar 16 '15 12:03

BenMorel


Video Answer


1 Answers

Try this code. Also you can press alt+enter at undefined properties and select Add @property it will help you to create phpdoc faster.

/**
 * @property Point $geometry
 */
class PointProxy extends Proxy {
  public function x() {
    return $this->geometry->
  }
}

add propertycompletion

like image 112
funivan Avatar answered Oct 09 '22 00:10

funivan