Monday, 26 August 2013

PHP Function restore_exception_handler()

Syntax

bool restore_exception_handler ( void );

Definition and Usage

This function is used after changing the exception handler function using set_exception_handler(), to revert to the previous exception handler (which could be the built-in or a user defined function).

Paramters

ParameterDescription
voidNA

Return Value

This function always returns TRUE.

Example

Following is the usage of this function:
<?php
function exception_handler1($exception) {
  echo "Uncaught exception 1: " , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler1');

function exception_handler2($exception) {
  echo "Uncaught exception 2: " , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler2');

# This will restore first exception.
restore_exception_handler();

throw new Exception('Uncaught Exception');
echo "Not Executed\n";
?> 
This will produce following result:
Uncaught exception 1: Uncaught Exception
If you will comment restore_exception_handler() function then you will have following result because previous exceptional handler will be overridden by subsequent call:
Uncaught exception 2: Uncaught Exception

No comments:

Post a Comment