php intlephense'未定义的方法'问题
我最近改用了支持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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论