note 104901 deleted from function.set-error-handler by danbrown

From: Date: Fri, 15 Jul 2011 14:23:10 +0000
Subject: note 104901 deleted from function.set-error-handler by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181569@lists.php.net to get a copy of this message
Note Submitter: zwarmapapa at hotmail dot com ---- Most complete one here, I used parts from other notes that are on this page <?php /*/ vars needed: $show_fatal_errors ( boolean ) $show_unknown_errors ( boolean ) $show_warnings ( boolean ) $show_notices ( boolean ) $known_errors ( array ) $known_warnings ( array ) $known_notices ( array ) /*/ function customErrorHandler( $error_id, $error_message, $error_file, $error_line ) { if( !(error_reporting() & $error_id) ) { // This error code is not included in error_reporting return; } // gets error type >> $error_type = ""; switch( $error_id ) { case E_ERROR: $error_type = "ERROR"; break; case E_PARSE: $error_type = "PARSE ERROR"; break; case E_CORE_ERROR: $error_type = "CORE ERROR"; break; case E_COMPILE_ERROR: $error_type = "COMPILE ERROR"; break; case E_USER_ERROR: $error_type = "USER ERROR"; break; case E_WARNING: $error_type = "WARNING"; break; case E_CORE_WARNING: $error_type = "CORE WARNING"; break; case E_COMPILE_WARNING: $error_type = "COMPILE WARNING"; break; case E_USER_WARNING: $error_type = "USER WARNING"; break; case E_NOTICE: $error_type = "NOTICE"; break; case E_USER_NOTICE: $error_type = "USER NOTICE"; break; default: $error_type = "UNKNOWN ERROR"; break; } if( $error_type == "UNKNOWN ERROR" ) { foreach( $GLOBALS['known_errors'] as $known_errors_error_id ) { if( $error_id == $known_errors_error_id ) { $error_type = "ERROR"; break; } } } if( $error_type == "UNKNOWN ERROR" ) { foreach( $GLOBALS['known_warnings'] as $known_warnings_error_id ) { if( $error_id == $known_warnings_error_id ) { $error_type = "WARNING"; break; } } } if( $error_type == "UNKNOWN ERROR" ) { foreach( $GLOBALS['known_notices'] as $known_notices_error_id ) { if( $error_id == $known_notices_error_id ) { $error_type = "NOTICE"; break; } } } // gets error type << // echoes error type data >> $echo = false; $abort = false; if( strpos($error_type, "UNKNOWN") !== false ) { if( $GLOBALS['show_unknown_errors'] ) { $echo = true; } } else { if( strpos($error_type, "ERROR") !== false ) { if( $GLOBALS['show_fatal_errors'] ) { $echo = true; $abort = true; } } if( strpos($error_type, "WARNING") !== false ) { if( $GLOBALS['show_warnings'] ) { $echo = true; } } if( strpos($error_type, "NOTICE") !== false ) { if( $GLOBALS['show_notices'] ) { $echo = true; } } } if( $echo ) { echo "<b>".$error_type."</b> [".$error_id."] ".$error_message."<br>\n"; echo "<b>".$error_file."</b> line <b>".$error_line."</b><br>\n"; if( $abort ) { echo "Aborting...<br>\n"; exit( 1 ); } else { echo "<br>\n"; } } // echoes error type data << /* Don't execute PHP internal error handler */ return true; } error_reporting( E_ALL ); set_error_handler( "customErrorHandler" ); ?>

« previous php.notes (#181569) next »