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!!