php intlephense'未定义的方法'问题

发布于 2025-02-09 14:13:50 字数 1070 浏览 0 评论 0原文

我最近改用了支持PHP的 intlephense 的IDE。 我不知道如何解决两个问题(请注意,该代码正确执行正确)。


#1。 。

$myobj = $this->myfactory->createObject($myparams);

本质上,我正在使用使用工厂来创建所需依赖关系的库 我访问如上所述的所讨论的工厂,其中createObject的返回类型是接口。 实现本工厂具有其他方法myFunc的默认类,因此我可以有效调用my_func(),但是IDE显示了一个错误,因为显然,它在接口中找不到。

是否没有简单的方法将接口投入到预期的混凝土类?


#2。未定义的方法“获取”

class MyClass{
    //...

    static function withAdditionalParams($myParams){
       return function ($defaultParamA, $defaultParamB) use ($myParams) {
           return $this->get(self::class)->__invoke($defaultParamA, $defaultParamB, $myParams);
       };
    }
}

在与上面的问题相似的同时,此方法更为复杂。由于我们正在处理关闭,因此在此上下文中的$ this实际上是指A di容器,而Intelephense认为它是指myClass实例。

是否没有办法明确说出$ this在此特定情况下是指吗?


对任何帮助或建议得到高度赞赏,谢谢!

I recently switched to an IDE that supports PHP's Intelephense.
There are two issues showing up that I don't know how to resolve (note, however, that the code executes correctly).


#1. Undefined method 'myfunc'

$myobj = $this->myfactory->createObject($myparams);

Essentially, I'm using a library that uses Factories to create the needed dependencies. I access the factory in question like stated above, where createObject's return type is an interface. The default class that implements this factory has the additional method myfunc, so I can validly call my_func(), but the IDE shows an error because it obviously can't find it in the interface.

Is there no easy way to cast the interface to the expected concrete class?


#2. Undefined method 'get'

class MyClass{
    //...

    static function withAdditionalParams($myParams){
       return function ($defaultParamA, $defaultParamB) use ($myParams) {
           return $this->get(self::class)->__invoke($defaultParamA, $defaultParamB, $myParams);
       };
    }
}

While being similar to the problem above, this one is a bit more complex. Since we're dealing with closures, the $this in this context actually refers to a DI Container, while Intelephense thinks it's referring to a MyClass instance.

Is there no way to explicitly say what $this refers to in this specific context?


Any help or advice is highly appreciated, thank you!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文