Suppose I have the class definition below. As it is, it generates two “notices” and a “warning,” indicated in the // comments below.
[code=php]
class Error {
private $errorHandler;
private $exceptionHandler;
public function __construct() {
// the next two lines produce an undefined property “notice”
$this->errorHandler = $this->defaultErrHandler;
$this->exceptionHandler = $this->defaultExcepHandler;
// the call to set_error_handler() generates an invalid callback “warning”
set_error_handler($this->errorHandler);
set_exception_handler($this->exceptionHandler);
}
function __destruct() {
}
public function defaultErrHandler ($errno, $errmsg, $errfile, $errline) {
die(“Error #”.$errno.” ‘”.$errmsg.”‘ in path ‘”.$errfile.”‘ at line “.
$errline);
}
public function defaultExcepHandler ($exceptionInstance) {
die(“Exception #”.$exceptionInstance->getCode().” ‘”.
$exceptionInstance->getMessage().”‘ in path ‘”.
$exceptionInstance->getFile().”‘ at line “.$exceptionInstance->getLine());
}
}
Should I be declaring the methods as static perhaps and then using static references [ self:: ]? What is ‘invalid’ about the callback…because it refers to an ‘undefined property’?