1

I set a set_exception_handler and a set_error_handler to properly handle exceptions and errors, still those do not catch 'fatal error'.

I tried this:

register_shutdown_function( "fatal_handler" );

function fatal_handler()
{
    FlashMessages::flashIt( 'message', 'Fatal error' );
    include( Settings::ABSPATH . '/src/views/message.php' );

    $error = error_get_last();

    if ( $error !== null ) {
        $errno = $error[ "type" ];
        $errfile = $error[ "file" ];
        $errline = $error[ "line" ];
        $errstr = $error[ "message" ];

        var_dump( $error );
    }
}

and i'm indeed able to dump the error, but there is no way to avoid the full stack error on top of page. How could I avoid displaying the error stack ?

enter image description here

Robert Brax
  • 4,735
  • 8
  • 32
  • 60
  • 2
    Dont dump it! Or lets say: remove developing code. And move the first to lines in the function into the if statement and check for `$error[ "type" ]==1` to catch only fatal errors in the shutdown function. – JustOnUnderMillions Mar 28 '17 at 12:55

1 Answers1

2
register_shutdown_function( "fatal_handler" );

function fatal_handler()
{
  $error = error_get_last();
  if ( $error[ "type" ] == 1) { //only fatal errors
    $errno = $error[ "type" ];
    $errfile = $error[ "file" ];
    $errline = $error[ "line" ];
    $errstr = $error[ "message" ];

    FlashMessages::flashIt("'$errstr' in $errfile in line $errline ", 'Fatal error');
    include( Settings::ABSPATH . '/src/views/message.php' );
  }
}

And dont show errors in production outputted by php.

ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);

How do I get PHP errors to display?

Turn Off Display Error PHP.ini

Community
  • 1
  • 1
JustOnUnderMillions
  • 3,650
  • 7
  • 11