mixed set_error_handler ( callable $error_handler [, int $error_types = E_ALL | E_STRICT ] )
Sets a user-defined error handler function
Sets a user function (error_handler) to handle errors in a script.
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.
5.2.0 The error handler must return FALSE to populate $php_errormsg. 5.0.0 The error_types parameter was introduced. 4.3.0 Instead of a function name, an array containing an object reference and a method name can also be supplied as the error_handler. 4.0.2 Three optional parameters for the error_handler user function was introduced. These are the filename, the line number, and the context.
Curso de Programación Web con Php - Clase 40 - Errores (Intro).mp4
0 Comment:
Post a Comment