Search code examples
error-handlingphp4

Is there a way to get the last error in php4


PHP 5 has error_get_last. Is there any way to completely or at least partially replicate the same functionality in PHP4.3?


Solution

  • Ripped from the PHP manual (courtesy of php at joert dot net):

    <?php
    if( !function_exists('error_get_last') ) {
        set_error_handler(
            create_function(
                '$errno,$errstr,$errfile,$errline,$errcontext',
                '
                    global $__error_get_last_retval__;
                    $__error_get_last_retval__ = array(
                        \'type\'        => $errno,
                        \'message\'        => $errstr,
                        \'file\'        => $errfile,
                        \'line\'        => $errline
                    );
                    return false;
                '
            )
        );
    
        function error_get_last() {
            global $__error_get_last_retval__;
            if( !isset($__error_get_last_retval__) ) {
                return null;
            }
            return $__error_get_last_retval__;
        }
    }
    ?>