PhpStorm - 流畅的界面

问题描述 投票:1回答:1

在类中使用fluent接口并尝试从此类的另一个函数逐个调用此类的函数时

F.E.

mainFunction()
{
    $this
        ->func1()
        ->func2()
        ->func3()
        ->func4()
        ->func5()
    ;
}

调用第4个函数后,PhpStorm无法将调用与函数定义连接,因此第5个函数定义获取信息

未使用的私有方法func5找不到私有方法的直接用法。

并且电话获得信息

在主题类中找不到Referenced方法中找不到的方法'func5'。

是否有可配置的限制设置?

php phpstorm
1个回答
0
投票

你遇到了一个已知的PhpStorm 6错误,正式版应该已修复 8.0.4(139.1803):WI-17801 Fluent-style chaining type loss with return this/static

如果将类名指定为返回类型,则可以解决此问题:

class FooBar
{
    // ...

    private function func1(): FooBar
    {
        return $this;
    }

    // ...  
}

或者,对于旧的PHP版本,

class FooBar
{
    // ...

    /**
     * @return FooBar
     */
    private function func1()
    {
        return $this;
    }

    // ...  
}
© www.soinside.com 2019 - 2024. All rights reserved.