note 109149 deleted from function.set-error-handler by joey
| From: | joey@php.net | Date: | Sat, 06 Apr 2013 22:33:31 +0000 |
| Subject: | note 109149 deleted from function.set-error-handler by joey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194363@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
Simply class, which capture all php errors. All in one...
Capture of course exceptions, which wasn't catched.
<?php
class Error
{
// CATCHABLE ERRORS
public static function captureNormal( $number, $message, $file, $line )
{
// Insert all in one table
$error = array( 'type' => $number, 'message' => $message,
'file' => $file, 'line' => $line );
// Display content $error variable
echo '<pre>';
print_r( $error );
echo '</pre>';
}
// EXTENSIONS
public static function captureException( $exception )
{
// Display content $exception variable
echo '<pre>';
print_r( $exception );
echo '</pre>';
}
// UNCATCHABLE ERRORS
public static function captureShutdown( )
{
$error = error_get_last( );
if( $error ) {
## IF YOU WANT TO CLEAR ALL BUFFER, UNCOMMENT NEXT LINE:
# ob_end_clean( );
// Display content $error variable
echo '<pre>';
print_r( $error );
echo '</pre>';
} else { return true; }
}
}
ini_set( 'display_errors', 1 );
error_reporting( -1 );
set_error_handler( array( 'Error', 'captureNormal' ) );
set_exception_handler( array( 'Error', 'captureException' ) );
register_shutdown_function( array( 'Error', 'captureShutdown' ) );
// PHP set_error_handler TEST
IMAGINE_CONSTANT;
// PHP set_exception_handler TEST
throw new Exception( 'Imagine Exception' );
// PHP register_shutdown_function TEST ( IF YOU WANT TEST THIS, DELETE PREVIOUS LINE )
imagine_function( );
?>
In output it will print table with details about triggered error.