Thursday, December 11, 2025
HomeLanguagesPHP restore_error_handler() Function

PHP restore_error_handler() Function

The restore_error_handler() function is an inbuilt PHP function that facilitates restoring the previous version of an error handler function.

Syntax:

restore_error_handler(): bool

Parameter: This function does not accept any parameter.

Return Value: This function will always return “true”.

Example 1: This example code demonstrates the restore_error_handler() function.

PHP




<?php
   
// Set a custom error handler
function custom_error_handler($errno,
$errstr, $errfile, $errline) {
    echo "Error: $errstr\n";
}
set_error_handler('custom_error_handler');
echo $age ;
 
// Restore the default error handler
restore_error_handler();
 
// Generate another error
echo $access_granted ;
?>


Output:

Error: Undefined variable $age
PHP Warning:  Undefined variable $access_granted 

Example 2: This example code also demonstrates the restore_error_handler() function.

PHP




<?php
function myownHandler($errno){
    echo  "Custom Error on line no = ".$errno ;
}
 
set_error_handler("myownHandler");
 
$value = 2 ;
if($value >1){
    echo "A custom error triggered" ;
}
 
restore_error_handler();
if($value >2){
    echo "A customer error triggered";
}
?>


Output:

A custom error triggered

Reference: https://www.php.net/manual/en/function.restore-error-handler.php

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32440 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6811 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12023 POSTS0 COMMENTS
Shaida Kate Naidoo
6943 POSTS0 COMMENTS
Ted Musemwa
7195 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS