Problem
I am open sourcing a trait which includes the magic method __call()
. During testing, I encountered a challenge when the parent class of the class using the trait contains the __call
method.
What I Tried
trait SomeTrait {
public function __call($method, array $parameters) {
// ...
return parent::__call($method, $parameters);
}
}
This results in the fatal error: Cannot access parent:: when current class scope has no parent
I also tried the following, based on some other answers:
return call_user_func_array([$this, '__call'], [$method, $parameters]);
This results in a Segmentation fault: 11. I imagine because of an infinite call loop.
Question
How can I invoke the parent's __call
method from within the __call
method of the trait?
If it is not possible from within the trait directly, how might I invoke the parent's __call
method otherwise?