vrana Tue Apr 5 08:00:25 2005 EDT
Modified files: /phpdoc/en/reference/errorfunc/functions restore-error-handler.xml Log: Meaningful example different from set_error_handler http://cvs.php.net/diff.php/phpdoc/en/reference/errorfunc/functions/restore-error-handler.xml?r1=1.8&r2=1.9&ty=u Index: phpdoc/en/reference/errorfunc/functions/restore-error-handler.xml diff -u phpdoc/en/reference/errorfunc/functions/restore-error-handler.xml:1.8 phpdoc/en/reference/errorfunc/functions/restore-error-handler.xml:1.9 --- phpdoc/en/reference/errorfunc/functions/restore-error-handler.xml:1.8 Tue Apr 5 06:51:53 2005 +++ phpdoc/en/reference/errorfunc/functions/restore-error-handler.xml Tue Apr 5 08:00:24 2005 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/errorfunc.xml, last change in rev 1.1 --> <refentry id="function.restore-error-handler"> <refnamediv> @@ -27,58 +27,30 @@ <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> + Decide if <function>unserialize</function> caused an error, then + restore the original error handler. </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) +function unserialize_handler($errno, $errstr) { - 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; - } + echo "Invalid serialized value.\n"; } -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); +$serialized = 'foo'; +set_error_handler('unserialize_handler'); +$original = unserialize($serialized); +restore_error_handler(); ?> ]]> </programlisting> - &example.outputs.similar; + &example.outputs; <screen> <![CDATA[ -My ERROR [512] Test error - -Warning: Test error in C:\Program Files\Apache Group\Apache2\htdocs\readdir.php on line 45 +Invalid serialized value. ]]> </screen> </example>