php-doc-en/reference/errorfunc/functions/restore-error-handler.xml

109 lines
3.1 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- splitted from ./en/functions/errorfunc.xml, last change in rev 1.1 -->
<refentry id="function.restore-error-handler">
<refnamediv>
<refname>restore_error_handler</refname>
<refpurpose>
Restores the previous error handler function
</refpurpose>
</refnamediv>
<refsect1>
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>restore_error_handler</methodname>
<void/>
</methodsynopsis>
<para>
Used after changing the error handler function using
<function>set_error_handler</function>, to revert to the previous error
handler (which could be the built-in or a user defined function). This
function always returns &true;.
</para>
<para>
See also <function>error_reporting</function>,
<function>set_error_handler</function>,
<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
// set the error reporting level for this script
error_reporting(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE);
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
switch ($errno) {
case E_USER_ERROR:
echo "<b>My ERROR</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 E_USER_WARNING:
echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
break;
case E_USER_NOTICE:
echo "<b>My NOTICE</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', E_USER_WARNING);
restore_error_handler(); // Will restore standard PHP handler
trigger_error('Test error', E_USER_WARNING);
?>
]]>
</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>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->