Date: 11/17/00
- Next message: Damien Seguy: "[PHP-DOC] cvs: phpdoc /fr/language operators.xml"
- Previous message: Martin Kraemer: "[PHP-DOC] cvs: phpdoc /de/functions apache.xml"
- Next in thread: Ron Chmara: "[PHP-DOC] cvs: phpdoc /en/functions errorfunc.xml"
- Maybe reply: Ron Chmara: "[PHP-DOC] cvs: phpdoc /en/functions errorfunc.xml"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
david Thu Nov 16 23:59:34 2000 EDT
Modified files:
/phpdoc/en/functions errorfunc.xml
Log:
update documentation for set_error_handler
Index: phpdoc/en/functions/errorfunc.xml
diff -u phpdoc/en/functions/errorfunc.xml:1.6 phpdoc/en/functions/errorfunc.xml:1.7
--- phpdoc/en/functions/errorfunc.xml:1.6 Fri Sep 15 09:09:43 2000
+++ phpdoc/en/functions/errorfunc.xml Thu Nov 16 23:59:34 2000
@@ -317,7 +317,14 @@
</para>
<para>
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).
+ </para>
+ <para>
+ The example below shows the handling of
internal execptions by triggering errors and handling them with a user
defined function:
<example>
@@ -334,46 +341,46 @@
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,10 +440,25 @@
----
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>
</programlisting>
</informalexample>
+ </para>
+ <para>
+ It is important to remember that the standard PHP error handler is completely
+ bypassed. <function>error_reporting</function> settings will have no effect
+ and your error handler will be called regardless - however you are still
+ able to read the current value of <function>error_reporting</function> and
+ act appropriately. Of particular note is that this value will be 0 if the
+ statement that caused the error was prepended by the
+ <link linkend="language.operators.errorcontrol">@ error-control
+ operator</link>.
+ </para>
+ <para>
+ Also note that it is your responsibility to <function>die</function> if
+ necessary. If the error-handler function returns, script execution
+ will continue with the next statement after the one that caused an error.
</para>
<para>
See also <function>error_reporting</function>,
- Next message: Damien Seguy: "[PHP-DOC] cvs: phpdoc /fr/language operators.xml"
- Previous message: Martin Kraemer: "[PHP-DOC] cvs: phpdoc /de/functions apache.xml"
- Next in thread: Ron Chmara: "[PHP-DOC] cvs: phpdoc /en/functions errorfunc.xml"
- Maybe reply: Ron Chmara: "[PHP-DOC] cvs: phpdoc /en/functions errorfunc.xml"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

