mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
update documentation for set_error_handler
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@35898 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
f08d4fefdb
commit
3c83f36fd6
1 changed files with 41 additions and 19 deletions
|
@ -317,7 +317,14 @@ error_reporting (E_ALL); // New syntax for PHP 3/4
|
|||
</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 (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>
|
||||
</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>,
|
||||
<function>restore_error_handler</function>,
|
||||
|
|
Loading…
Reference in a new issue