note 91542 deleted from function.set-error-handler by joey
| From: | joey@php.net | Date: | Tue, 06 Dec 2011 18:49:36 +0000 |
| Subject: | note 91542 deleted from function.set-error-handler by joey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184956@lists.php.net to get a copy of this message | ||
Note Submitter: Johan "Josso" Jensen
----
If you use set_error_handler the default PHP error handler is deactivated.
Be ware of that if you have error_log enabled in php.ini it is included in the PHP error handler
which is deactivated and you'll of course not going to get your log updated.
So be sure that you use the PHP-function error_log() in your custom error handler.
An example:
<?php
function myErrorHandler($errno, $errstr, $errfile, $errline) {
switch ($errno) {
case E_NOTICE:
case E_USER_NOTICE:
$errors = "Notice";
break;
case E_WARNING:
case E_USER_WARNING:
$errors = "Warning";
break;
case E_ERROR:
case E_USER_ERROR:
$errors = "Fatal Error";
break;
default:
$errors = "Unknown";
break;
}
if (ini_get("display_errors"))
printf ("<br />\n<b>%s</b>: %s in <b>%s</b> on line
<b>%d</b><br /><br />\n", $errors, $errstr, $errfile, $errline);
if (ini_get('log_errors'))
error_log(sprintf("PHP %s: %s in %s on line %d", $errors, $errstr, $errfile,
$errline));
return true;
}
// set to the user defined error handler
set_error_handler("myErrorHandler");
?>
In this error handler I check if the display_errors is set and then outputs the error if it is (the
exact same as PHP5 would) and then I check if the log_errors is enabled.
error_log() can also be used for sending an email but check the manual for that. ;)