Skip to main content
Active reading [<https://en.wiktionary.org/wiki/want#Verb> <https://en.wikipedia.org/wiki/PHP>]. Active reading. In English, the subjective form of the singular first-person pronoun, "I", is capitalized, along with all its contractions such as I'll and I'm.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

JustHere is just a nice trick to get the current error_handler method =)

<?php
    register_shutdown_function('__fatalHandler'); 

    function __fatalHandler()
    {
    $error     $error = error_get_last();

        //check Check if it's a core/fatal error,. otherwiseOtherwise, it's a normal shutdown
        if($error !== NULL && $error['type'] === E_ERROR) { 

            //Bit It is a bit hackish, but the set_exception_handler
            // will return the old handler
            function fakeHandler() { } 

            $handler = set_exception_handler('fakeHandler');
            restore_exception_handler();
            if($handler !== null) { 
                call_user_func(
                    $handler,
                    new ErrorException(
                        $error['message'],
                        $error['type'],
                        0,
                        $error['file'],
                        $error['line']));
            }
            exit;
        }
    }
?>

Also i wan'tI want to note that if you call

<?php
    ini_set('display_errors', false);
?>

PhpPHP stops displaying the error. Otherwise, otherwise the error text will be send to the client prior to your error handler.

Just a nice trick to get the current error_handler method =)

<?php
register_shutdown_function('__fatalHandler');
function __fatalHandler()
{
    $error      = error_get_last();

    //check if it's a core/fatal error, otherwise it's a normal shutdown
    if($error !== NULL && $error['type'] === E_ERROR) {
        //Bit hackish, but the set_exception_handler will return the old handler
        function fakeHandler() { }
        $handler = set_exception_handler('fakeHandler');
        restore_exception_handler();
        if($handler !== null) { 
            call_user_func($handler, new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
        }
        exit;
    }
}
?>

Also i wan't to note that if you call

<?php
ini_set('display_errors', false);
?>

Php stops displaying the error, otherwise the error text will be send to the client prior to your error handler

Here is just a nice trick to get the current error_handler method =)

<?php
    register_shutdown_function('__fatalHandler'); 

    function __fatalHandler()
    {
        $error = error_get_last();

        // Check if it's a core/fatal error. Otherwise, it's a normal shutdown
        if($error !== NULL && $error['type'] === E_ERROR) { 

            // It is a bit hackish, but the set_exception_handler
            // will return the old handler
            function fakeHandler() { } 

            $handler = set_exception_handler('fakeHandler');
            restore_exception_handler();
            if($handler !== null) {
                call_user_func(
                    $handler,
                    new ErrorException(
                        $error['message'],
                        $error['type'],
                        0,
                        $error['file'],
                        $error['line']));
            }
            exit;
        }
    }
?>

Also I want to note that if you call

<?php
    ini_set('display_errors', false);
?>

PHP stops displaying the error. Otherwise, the error text will be send to the client prior to your error handler.

Source Link
Sander Visser
  • 4.3k
  • 1
  • 32
  • 44

Just a nice trick to get the current error_handler method =)

<?php
register_shutdown_function('__fatalHandler');
function __fatalHandler()
{
    $error      = error_get_last();

    //check if it's a core/fatal error, otherwise it's a normal shutdown
    if($error !== NULL && $error['type'] === E_ERROR) {
        //Bit hackish, but the set_exception_handler will return the old handler
        function fakeHandler() { }
        $handler = set_exception_handler('fakeHandler');
        restore_exception_handler();
        if($handler !== null) { 
            call_user_func($handler, new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
        }
        exit;
    }
}
?>

Also i wan't to note that if you call

<?php
ini_set('display_errors', false);
?>

Php stops displaying the error, otherwise the error text will be send to the client prior to your error handler