Reputation: 522
I have two classes A and B and A class has property of B class object. When I try to call this B class function phpstorm does not show any suggestion. I'm doing like this
Class A {
public $b;
function __construct($b) {
$this->b = $b;
}
public function someWork() {
$this->b->anotherWork();
}
}
Class B {
public function callA() {
$a = new A($this);
$a->someWork();
}
public function anotherWork() {
echo "do somethings";
}
}
$b = new B();
$b->callA();
when typing $this->b->anotherWork() phpstorm does not show any suggestion. Is there any way to get suggestion of all class B function from this b variable.
Upvotes: 0
Views: 127
Reputation:
Use type hinting.
In class A declare your constructor like this:
public function _construct(B $b) {
// do stuff
}
This also allows PHP to type check the argument at runtime and report an error if it is wrong.
Upvotes: 1
Reputation: 426
Try type hinting on the variable and/or PHPDoc on the function and it should work great.
Class A {
/** @var B */
public $b;
/**
* @param B $b
*/
function __construct($b) {
$this->b = $b;
}
public function someWork() {
$this->b->anotherWork();
}
}
Upvotes: 3