Building a basic error handler with custom error types
’.$error_message,’ (An error type ‘,$error_type,’ occurred). The administrator has been notified. This page might not function correctly.
’;
break;
case E_WARNING:
case E_USER_WARNING:
// Add your own code here!
echo ‘’.$error_message,’ (An error type ‘,$error_type,’ occurred). The administrator has been notified. This page might not function correctly.
’;
break;
case E_NOTICE:
case E_USER_NOTICE:
// Add your own code here!
echo ‘’.$error_message,’ (An error type ‘,$error_type,’ occurred). The administrator has been notified. This page might not function correctly.
’;
break;
case BIG_SCARY_ERROR:
echo ‘A *huge* scary error has been seen skulking around on line ‘.$error_line.’ of ‘.$error_file.’! It\’s shouting « ‘.$error_message.' »‘;
break;
}
return true;
}
}
?>
To use this error handler, put in in a file, and include it into your script. Then, instantiate it (eg $error_handler = new error_handler() ). The whenever an error occurs, the class will catch it. To trigger your own errors do:
trigger_error(‘error message typed here’, E_USER_ERROR);
(where the bit in capitals is the type you want to trigger).
So you can do this to trigger a custom error type:
trigger_error(‘I’m going to eat your PHP code!!! Bwahahahahaaa’, BIG_SCARY_ERROR);