Method not found in class
Hi,
I'm french so first : Apologize for my accent !
I have a warning of method not found because the class is not found (null)
Method not found in class
I give you an example of code that give me this problem :
Class A {
public function test() {
echo "A::test()";
}
}
Class ACollection {
protected $aArray = array();
public function add($name, $value) {
$this->aArray[$name] = $value;
}
public function get($name) {
return $this->aArray[$name];
}
}
$a = new A();
$aCollection = new ACollection();
$aCollection->add('a', $a);
$aCollection->get('a')->test();
Have you a solution to remove this warning ?
Should I change somethings in my configuration ?
Or change my code ?
I'm discovering PhpStorm, I'm already fond of. I hope I'll find a solution !
Florent
Please sign in to leave a comment.
Hi there,
Will get() method always return instances of the same class?
If so -- you can add proper PHPDoc for get() method -- code completion will stll be available:
/** * Some very useful function * * @param string $name SomeDescription * @return A */ public function get($name) { return $this->aArray[$name]; }If it will return mixed types .. you could add this kind of PHPDoc comment (the only difference is "mixed" instead of concrete type "A"):
/** * Some very useful function * * @param string $name SomeDescription * @return mixed */ public function get($name) { return $this->aArray[$name]; }This way ->test() will no longer be marked as unknown .. but there will be no code completion (since IDE does not know what type return value of get() is -- it is known ONLY during runtime).
In any case -- use PHPDoc to help IDE as well as yourself (self-documentation).
P.S.
If get() has a limited set of return types / keys .. check DynamicReturnTypePlugin pligin -- it may help here (you should be able to hardcode/specify what key will return what type).
Top !
Thanks for your rapidity and your accuracy.
Florent