Error Handling In PHP (part 2) - Back To Class
(Page 7 of 8 )
If you're not a big fan of rolling your own code, you might find it instructive and useful to download the free, open-source ErrorHandler class from
http://www.phpclasses.org/browse.html/package/345. Created by Gyozo Papp, this PHP class is a robust, full-featured error handler that can easily be integrated into your application code.
The ErrorHandler class comes with some very interesting features: the ability to dump errors to a separate console window so that your primary interface is not disrupted, to include in that error report the source code which caused the error, and to append customized error messages or variable context to the error report. Obviously, it also supports error logging (to a file, an email message, the system logger, or all three) and can catch and replace PHP's error messages with a user-defined error template.
Here's a small example of how it works - take a look at the manual included with the class for more examples and information.
report_layout('LOGGING', FILE_LOG, 'error.log');
// don't display symbol table
$error->report_layout('CONTEXT', FALSE);
// uncomment this to hide errors and display a customized error template
// $error->set_silent(TRUE);
// $error->set_silent("error.html");
// generate some errors
include('non.existent.file');
mysql_connect("localhost", "baduser", "badpassword");
?>
And here's what it looks like:

Next: Endgame >>
More PHP Articles
More By icarus, (c) Melonfire