I have a class A
and class B
which inherits from class A
, and I want to run some checks before I run the function.
class A {
public class __call($name, $params) {
if (method_exists?($this, $name)) {
$result = call_user_func_array([$this, $name], $params);
return $result;
}
}
}
class B {
private function hello() {
echo "Hello"
}
}
I was expecting that when I call:
$b = new B();
$b->hello();
It will call __call
and then execute private function hello
, but it starts infinite loop, it looks that call_user_func_array
triggers __call
again.
But the code works if I create hello
function in class A
Is this expected behavior? Is there anything I can do to prevent this?