I just finished creating an error handling class in PHP. The source code is here:
http://www.sccode.com/projects/filem...src/error.phps
The documentation here:
http://www.sccode.com/projects/filem...r_handler.html
Feel free to use it if you like it and if you have any comments or suggestions, please let me know. Here's a quick code snippet demonstrating its use:
PHP Code:
<?php
include_once 'error.php';
$err = &new error;
$err->logpath = 'myerror.log';
$err->fatal_error_function = Array('friendly_exit');
$err->email_on_errors = true;
$err->email_send = 2;
$err->admin_email = 'me@mydomain.com';
$err->email_subject = 'My Custom Error Script';
/* this will produce a notice */
echo ($undefiend);
echo ('this will be seen');
/* start an output buffer */
ob_start();
/* so will this */
$defined = hello;
echo ('you will never see this');
/* this will produce a warning */
fputs($none, 'error');
/* this will produce a fatal error and end the script */
trigger_error('This is a fatal error. Bye bye.', E_USER_ERROR);
function friendly_exit()
{
/* clear the current ouput buffer (if any)*/
if (ob_get_level() >= 1) ob_end_clean();
echo ('<h3>Error</h3>');
echo ('<p>I\\'m sorry, this application has had to terminate. Our maintainance team are aware of the problem and ');
echo ('are working to rectify it as soon as possible.</p>');
}
?>