I'm trying to make some kind of error-handler in one of my classes.
Therefore my class has a $error
variable. If it is true, it should print a message.
This procedure shoud happen everytime before a function of this class is called
I have tried the approach of the magic method __call(), mentioned in this answer: SO Answer
Unfortunately it doesn't work.
class XXX extends YYY{
public $error;
public $var;
function __construct($var)
{
$this->var = $var;
$this->error = true; //test the error process
}
private function before(){
if($this->error)
{
echo "something went wrong"; die;
}
}
private function test(){
echo "test", PHP_EOL;
}
public function __call($method,$arguments) {
if(method_exists($this, $method)) {
$this->before();
return call_user_func_array(array($this,$method),$arguments);
}
}
}
When I call:
$a = new XXX($var);
$a->test();
The output is still:
/*
* Output:
* test
*/
Any Ideas would be very appreciated.
Thanks