Customizing the PHP Error Handler
By Tony Marston2005-04-09
Calling the error handler
Certain types of error, such as trying to access a variable which has not yet been defined, will be triggered automatically by PHP. As these are at the E_NOTICE level they will fall through the error handler and allow processing to continue. It would be possible to do something with these errors, such as writing them out to a log file, if you so desired.
It is also possible to trigger the error handler by using the trigger_error() function. Here for example we are using the simple error string 'SQL' to force the error handler to extract the contents of mysql_errno() and mysql_error().
For non-sql errors a specific error string should be supplied.
$result = mysql_query($query, $dbconnect) or trigger_error("SQL", E_USER_ERROR);
if ($divisor == 0) {
trigger_error ("Cannot divide by zero", E_USER_ERROR);
} // if
if (!function_exists('xslt_create')) {
trigger_error('XSLT functions are not available.', E_USER_ERROR);
} // if
Tutorial Pages:
» Customising the PHP Error Handler
» Introduction
» Creating the Error Handler
» Calling the error handler
» Summary
