Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Customizing the PHP Error Handler

By Tony Marston
2005-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().

      

$result = mysql_query($query, $dbconnect) or trigger_error("SQL", E_USER_ERROR);
For non-sql errors a specific error string should be supplied.

      

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


 | Bookmark
Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1

Ask A Question
characters left.