13th February 2008 - 4 minutes read time
The set_error_handler() function can be used in PHP to allow you to catch any run time errors and act accordingly. This function can take two parameters:
- Error Handler : This a string which is the name of the function that will be called if an error is encountered.
- Error Types (optional) : This is an optional parameter used to tell PHP on what error codes to act. This is the same error reporting setting.
The function that is defined in the function must have the following footprint as a minimum.
function handler($errno,$errstr)
You can also get a lot more information out by using other parameters.
function handler($errno,$errstr,$errfile,$errline,$errcontext)
Here is some code that will print two errors to screen with as much information as possible.