note 91542 added to function.set-error-handler

From: Date: Tue, 16 Jun 2009 12:08:17 +0000
Subject: note 91542 added to function.set-error-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-156911@lists.php.net to get a copy of this message
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. ;) ---- Server IP: 195.184.96.15 Probable Submitter: 93.165.24.6 ---- Manual Page -- http://www.php.net/manual/en/function.set-error-handler.php Edit -- https://master.php.net/note/edit/91542 Del: integrated -- https://master.php.net/note/delete/91542/integrated Del: useless -- https://master.php.net/note/delete/91542/useless Del: bad code -- https://master.php.net/note/delete/91542/bad+code Del: spam -- https://master.php.net/note/delete/91542/spam Del: non-english -- https://master.php.net/note/delete/91542/non-english Del: in docs -- https://master.php.net/note/delete/91542/in+docs Del: other reasons-- https://master.php.net/note/delete/91542 Reject -- https://master.php.net/note/reject/91542 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156911) next »