note 104901 added to function.set-error-handler

From: Date: Thu, 14 Jul 2011 16:02:54 +0000
Subject: note 104901 added to function.set-error-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-181502@lists.php.net to get a copy of this message
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" ); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 83.117.76.97 ---- Manual Page -- http://www.php.net/manual/en/function.set-error-handler.php Edit -- https://master.php.net/note/edit/104901 Del: integrated -- https://master.php.net/note/delete/104901/integrated Del: useless -- https://master.php.net/note/delete/104901/useless Del: bad code -- https://master.php.net/note/delete/104901/bad+code Del: spam -- https://master.php.net/note/delete/104901/spam Del: non-english -- https://master.php.net/note/delete/104901/non-english Del: in docs -- https://master.php.net/note/delete/104901/in+docs Del: other reasons-- https://master.php.net/note/delete/104901 Reject -- https://master.php.net/note/reject/104901 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181502) next »