mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Added example
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@183591 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
086ab8e5ef
commit
b18c565926
1 changed files with 63 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- splitted from ./en/functions/errorfunc.xml, last change in rev 1.1 -->
|
||||
<refentry id="function.restore-error-handler">
|
||||
<refnamediv>
|
||||
|
@ -26,6 +26,68 @@
|
|||
<function>restore_exception_handler</function>,
|
||||
<function>trigger_error</function>.
|
||||
</para>
|
||||
<para>
|
||||
The example below shows the handling of internal exceptions by
|
||||
triggering errors and handling them with a user defined function. It then
|
||||
restores the original PHP error handling:
|
||||
<example>
|
||||
<title>
|
||||
Error handling with <function>set_error_handler</function>,
|
||||
<function>trigger_error</function> and
|
||||
<function>restore_error_handler</function>
|
||||
</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// redefine the user error constants - PHP 4 only
|
||||
define("FATAL", E_USER_ERROR);
|
||||
define("ERROR", E_USER_WARNING);
|
||||
define("WARNING", E_USER_NOTICE);
|
||||
|
||||
// set the error reporting level for this script
|
||||
error_reporting(FATAL | ERROR | WARNING);
|
||||
|
||||
// error handler function
|
||||
function myErrorHandler($errno, $errstr, $errfile, $errline)
|
||||
{
|
||||
switch ($errno) {
|
||||
case FATAL:
|
||||
echo "<b>My FATAL</b> [$errno] $errstr<br />\n";
|
||||
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:
|
||||
echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
|
||||
break;
|
||||
case WARNING:
|
||||
echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
|
||||
break;
|
||||
default:
|
||||
echo "My unkown error type: [$errno] $errstr<br />\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
set_error_handler("myErrorHandler");
|
||||
trigger_error('Test error', ERROR);
|
||||
|
||||
restore_error_handler(); // Will restore standard PHP handler
|
||||
trigger_error('Test error', ERROR);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.similar;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
My ERROR [512] Test error
|
||||
|
||||
Warning: Test error in C:\Program Files\Apache Group\Apache2\htdocs\readdir.php on line 45
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
|
|
Loading…
Reference in a new issue