I am building the basics of my error reporting system, basically I have these two bad boys set up
class System {
public function __construct(){
set_exception_handler(array($this, 'handleExceptions'));
set_error_handler(array($this, 'handleGenericError'));
}
public function handleExceptions(\Exception $e){
echo "<pre>".print_r($e, true)."</pre>";
}
public function handleGenericError($no, $msg, $file, $line, $context){
$msg .= ' in ['.$file.'] on line ['.$line.']';
throw new \Exception($msg);
}
}
Then I provoke an error in the __construct method, after the declarations. Statements like
public function __construct(){
....
echo $undefined_variable;
}
And
public function __construct(){
....
echo $this->undefined_variable;
}
Seem to go well, printing a nice readable exception message, but if I do this
public function __construct(){
....
echo $this->$undefined_variable;
}
I get an uncaught exception. Why is that? The exception being thrown is from the handleGenericError method, I can tell because it has [] around it and stuff. This is a little confusing. :/