Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

restore_error_handler()

Example

Restore the previous error handler after it has been changed using the set_error_handler() function.

<?php
// A user-defined error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline) {
    echo “<b>Custom error:</b> [$errno] $errstr<br>”;
    echo ” Error on line $errline in $errfile<br>”;
}

// Set user-defined error handler function
set_error_handler(“myErrorHandler”);

$test=2;

// Trigger error
if ($test>1) {
    trigger_error(“A custom error has been triggered”);
}

// Restore previous error handler
restore_error_handler();

// Trigger error again
if ($test>1) {
    trigger_error(“A custom error has been triggered”);
}
?>

Definition and Usage

The restore_error_handler() function restores the previous error handler.

Use this function to revert to the previous error handler after it has been modified with the set_error_handler() function.

Tip: The previous error handler might be either a built-in error handler or a user-defined function.

Syntax

restore_error_handler();

Technical Details

Return Value:

Always returns TRUE.

PHP Version:

4.0.1+