1

假设我有一组类

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...
    }

}

如何让 PhpStorm 按照方法中的假设进行类型提示工作doesntWork?我真的很生气,因为我的很多工作都依赖于在这样的特征中使用主类方法,而且我在 PhpStorm 中得到了很多令人分心的黄色......

4

2 回答 2

4

你现在不能做太多事情——这是一个 IDE 问题。

https://youtrack.jetbrains.com/issue/WI-35952 - 观看这张票(star/vote/comment)以获得任何进展的通知。

相关:https ://youtrack.jetbrains.com/issue/WI-39004

于 2018-03-07T10:41:33.393 回答
1

事实证明有一个解决方法。在这种情况下,

/**
* @method \Namespace\Name\B getB
*/
trait Dummy { ... }

有点难看但有效

于 2018-03-07T10:48:16.433 回答