PHP 5.6.0 released

restore_error_handler

(PHP 4 >= 4.0.1, PHP 5)

restore_error_handlerRestores the previous error handler function

Description

bool restore_error_handler ( void )

Used after changing the error handler function using set_error_handler(), to revert to the previous error handler (which could be the built-in or a user defined function).

Return Values

This function always returns TRUE.

Examples

Example #1 restore_error_handler() example

Decide if unserialize() caused an error, then restore the original error handler.

<?php
function unserialize_handler($errno$errstr)
{
    echo 
"Invalid serialized value.\n";
}

$serialized 'foo';
set_error_handler('unserialize_handler');
$original unserialize($serialized);
restore_error_handler();
?>

The above example will output:

Invalid serialized value.

Notes

Note:

Calling restore_error_handler() from the error_handler function is ignored.

See Also

add a note add a note

User Contributed Notes 2 notes

up
2
lsole at maresme dot net
10 years ago
As the docs say, restore_error_handler() revert to the *previous error handler*... even if it is the same. A bug made me set twice my custom error handler and later when I was calling restore_error_handler() to restore the built-in handler nothing seemed to happen... this puzzled me for a while!
up
1
edgarinvillegas at hotmail dot com
6 years ago
Isolde is kind of wrong. The error handlers are stacked with set_error_handler(), and popped with restore_error_handler(). Here i put an example:

<?php
    mysql_connect
("inexistent"); //Generate an error. The actual error handler is set by default

   
function foo1() {echo "<br>Error foo1<br>";}
    function
foo2() {echo "<br>Error foo2<br>";}
    function
foo3() {echo "<br>Error foo3<br>";}
   
   
set_error_handler("foo1");    //current error handler: foo1
   
set_error_handler("foo2");    //current error handler: foo2
   
set_error_handler("foo3");    //current error handler: foo3
   
   
mysql_connect("inexistent");   
   
restore_error_handler();        //now, current error handler: foo2
   
mysql_connect("inexistent");    
   
restore_error_handler();        //now, current error handler: foo1
   
mysql_connect("inexistent");
   
restore_error_handler();        //now current error handler: default handler
   
mysql_connect("inexistent");
   
restore_error_handler();        //now current error handler: default handler (The stack can't pop more)
?>
To Top