note 109149 added to function.set-error-handler
| From: | Anonymous | Date: | Sat, 23 Jun 2012 12:57:56 +0000 |
| Subject: | note 109149 added to function.set-error-handler | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188768@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 46.149.222.50
----
Manual Page -- http://www.php.net/manual/en/function.set-error-handler.php
Edit -- https://master.php.net/note/edit/109149
Del: integrated -- https://master.php.net/note/delete/109149/integrated
Del: useless -- https://master.php.net/note/delete/109149/useless
Del: bad code -- https://master.php.net/note/delete/109149/bad+code
Del: spam -- https://master.php.net/note/delete/109149/spam
Del: non-english -- https://master.php.net/note/delete/109149/non-english
Del: in docs -- https://master.php.net/note/delete/109149/in+docs
Del: other reasons-- https://master.php.net/note/delete/109149
Reject -- https://master.php.net/note/reject/109149
Search -- https://master.php.net/manage/user-notes.php