From 3c83f36fd6baa4473a5e2bf6254d3cf6a5017d48 Mon Sep 17 00:00:00 2001 From: David Croft Date: Fri, 17 Nov 2000 07:59:34 +0000 Subject: [PATCH] update documentation for set_error_handler git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@35898 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/errorfunc.xml | 60 ++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/functions/errorfunc.xml b/functions/errorfunc.xml index ac4320a649..bcb5484dbb 100644 --- a/functions/errorfunc.xml +++ b/functions/errorfunc.xml @@ -317,7 +317,14 @@ error_reporting (E_ALL); // New syntax for PHP 3/4 The user function needs to accept 2 parameters: the error code, and a - string describing the error. The example below shows the handling of + string describing the error. From PHP 4.0.2, an additional 3 optional + parameters are supplied: the filename in which the error occured, the + line number in which the error occured, and the context in which the + error occured (an array that points to the active symbol table at the + point the error occurred). + + + The example below shows the handling of internal execptions by triggering errors and handling them with a user defined function: @@ -334,46 +341,46 @@ define (ERROR,E_USER_WARNING); define (WARNING,E_USER_NOTICE); // set the error reporting level for this script -error_reporting (FATAL + ERROR + WARNING); +error_reporting (FATAL | ERROR | WARNING); // error handler function -function myErrorHandler ($errno, $errstr) { - switch ($errno) { - case FATAL: +function myErrorHandler ($errno, $errstr, $errfile, $errline) { + switch ($errno) { + case FATAL: echo "<b>FATAL</b> [$errno] $errstr<br>\n"; - echo " Fatal error in line ".__LINE__." of file ".__FILE__; + echo " Fatal error in line ".$errline." of file ".$errfile; echo ", PHP ".PHP_VERSION." (".PHP_OS.")<br>\n"; echo "Aborting...<br>\n"; exit -1; break; - case ERROR: + case ERROR: echo "<b>ERROR</b> [$errno] $errstr<br>\n"; break; - case WARNING: + case WARNING: echo "<b>WARNING</b> [$errno] $errstr<br>\n"; break; default: echo "Unkown error type: [$errno] $errstr<br>\n"; break; - } + } } // function to test the error handling function scale_by_log ($vect, $scale) { - if ( !is_numeric($scale) || $scale <= 0 ) - trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", + if ( !is_numeric($scale) || $scale <= 0 ) + trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", FATAL); - if (!is_array($vect)) { + if (!is_array($vect)) { trigger_error("Incorrect input vector, array of values expected", ERROR); return null; - } - for ($i=0; $i<count($vect); $i++) { + } + for ($i=0; $i<count($vect); $i++) { if (!is_numeric($vect[$i])) - trigger_error("Value at position $i is not a number, using 0 (zero)", - WARNING); + trigger_error("Value at position $i is not a number, using 0 (zero)", + WARNING); $temp[$i] = log($scale) * $vect[$i]; - } - return $temp; + } + return $temp; } // set to the user defined error handler @@ -433,11 +440,26 @@ NULL ---- vector d - fatal error <b>FATAL</b> [256] log(x) for x <= 0 is undefined, you used: scale = -2.5<br> - Fatal error in line 16 of file trigger_error.php, PHP 4.0.1pl2 (Linux)<br> + Fatal error in line 36 of file trigger_error.php, PHP 4.0.2 (Linux)<br> Aborting...<br> + + It is important to remember that the standard PHP error handler is completely + bypassed. error_reporting settings will have no effect + and your error handler will be called regardless - however you are still + able to read the current value of error_reporting and + act appropriately. Of particular note is that this value will be 0 if the + statement that caused the error was prepended by the + @ error-control + operator. + + + Also note that it is your responsibility to die if + necessary. If the error-handler function returns, script execution + will continue with the next statement after the one that caused an error. + See also error_reporting, restore_error_handler,