phpphpstormphp-7type-hintingphpstorm-2017.2

PhpStorm not typehinting class method return types in trait


Suppose i have a set of classes

class A {

    use Dummy;

    function getB() : B { ... }

}

class B {

    function foo() { ... }

}



trait Dummy {

    function works() {
        if ($this instanceof A)
            $this -> getB() -> foo();   // Typehinting works
    }

    function doesntWork() {
        $this -> getB() -> foo(); // Method foo not found in...
    }

}

How do I get PhpStorm to get typehinting work as supposed in method doesntWork? I really get annoyed by this because lots of my work relies on using main class methods in traits like this and I get lots of distracting yellow color in PhpStorm...


Solution

  • You cannot do much right now -- it's an IDE issue.

    https://youtrack.jetbrains.com/issue/WI-35952 -- watch this ticket (star/vote/comment) to get notified on any progress.

    Related: https://youtrack.jetbrains.com/issue/WI-39004