简体   繁体   中英

IntelliJ IDEA and PHP inheritance

I am running into trouble making IntelliJ IDEA display inherited methods correctly.

I have an abstract BaseController class holding two protected field variables (f3 and db). In the extending ForumController class, db works fine, but the static f3 does not (see screenshots below).

The framework used is FatFree, if that helps.

抽象的BaseController扩展ForumController

Any help or suggestion would be highly appreciated.

Use the tags of phpdoc to document all classes, properties and methods. IntelliJ uses those to determine what possible values a property or variable may hold. In this case documenting the $f3 property could be sufficient:

/**
 * @var Base
 */
protected $f3;

After typing the first /** on the line before the property and pressing enter IntelliJ will generate a docblock for you with what it knows already.

In fatfree framework, the instance of Base class ($f3 in your code) is passed to the constructor, so you can use type hinting there:

public function __construct(Base $f3){
    $this->f3 = $f3;

Though retrieving the instance from the registry via the static call Base::instance(); and using phpdoc comments as in the accepted answer is fine as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM