set_error_handler in classes
Posted: Sat Jan 15, 2005 12:59 am
I'm new to custom error reporting, but here's a function I adapted from PHP and MySQL Web Development:
However, the book isn't all that great cause it's built off of register_globals being on, so I doubt the function works in the first place.
Anyway, once it does work, I hope you can see what I'm trying to do. Based on the errorno, i.e. 1 being E_ERROR, 512 being E_USER_WARNING, etc. it will throw the error into an array, then I'll check it later, based on there continue or break, etc.
Sooooooo, I guess I'm asking how I can make this function work without register_globals. The function parameters seem... off to me to say the least. Doesn't say anything in the book about an alternative. Once the basic function works, I'd like to throw it into a class so when runtime errors occur with class functions, theses errors will show and not the ugly ones.
In a lil over my head, hopefully yall can help.
Code: Select all
function custom_error($errnum, $errstring, $file, $lineno){
switch($errnum){
case 1:
$this->errorї] = "A fatal error has occured. All scripts have been terminated and an error report is being filed.";
//include 'error_report.php';
break;
case 2:
$this->errorї] = "A non-fatal error has occured. While not a threat to what you were doing, it has caused the scripts to
terminate. An error report is being filed.";
//include 'error_report.php';
break;
case 4:
$this->errorї] = "A parse error has occured. This means there is an error in the internal structure of the code. We apologize
for the inconvenience.";
//include 'error_report.php';
break;
case 8:
$this->errorї] = "We're sorry, but an error has occurred. An error report is being made.";
//include 'error_report.php';
break;
case 256:
$this->errorї] = "A user triggered error has occured. To better serve you, it's imperative that you let us know what you were doing when
the error occurred.";
//include 'error_report.php';
break;
case 512:
$this->errorї] = "A user triggered error has occured. To better serve you, it's imperative that you let us know what you were doing when
the error occurred.";
//include 'error_report.php';
break;
case 1024:
$this->errorї] = "A user triggered error has occured. To better serve you, it's imperative that you let us know what you were doing when
the error occurred.";
//include 'error_report.php';
break;
}Anyway, once it does work, I hope you can see what I'm trying to do. Based on the errorno, i.e. 1 being E_ERROR, 512 being E_USER_WARNING, etc. it will throw the error into an array, then I'll check it later, based on there continue or break, etc.
Sooooooo, I guess I'm asking how I can make this function work without register_globals. The function parameters seem... off to me to say the least. Doesn't say anything in the book about an alternative. Once the basic function works, I'd like to throw it into a class so when runtime errors occur with class functions, theses errors will show and not the ugly ones.
In a lil over my head, hopefully yall can help.