. /** * @package CoreAPI * @subpackage ErrorAPI * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org * @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.net * @link http://www.mantisbt.org */ $g_error_parameters = array(); $g_error_handled = false; $g_error_proceed_url = null; $g_error_send_page_header = true; set_error_handler( 'error_handler' ); /** * Default error handler * * This handler will not receive E_ERROR, E_PARSE, E_CORE_*, or E_COMPILE_* * errors. * * E_USER_* are triggered by us and will contain an error constant in $p_error * The others, being system errors, will come with a string in $p_error * * @access private * @param int p_type contains the level of the error raised, as an integer. * @param string p_error contains the error message, as a string. * @param string p_file contains the filename that the error was raised in, as a string. * @param int p_line contains the line number the error was raised at, as an integer. * @param array p_context to the active symbol table at the point the error occurred (optional) * @uses lang_api.php * @uses config_api.php * @uses compress_api.php * @uses database_api.php (optional) * @uses html_api.php (optional) */ function error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) { global $g_error_parameters, $g_error_handled, $g_error_proceed_url; global $g_lang_overrides; global $g_error_send_page_header; # check if errors were disabled with @ somewhere in this call chain if( 0 == error_reporting() ) { return; } $t_lang_pushed = false; $t_db_connected = false; if( function_exists( 'db_is_connected' ) ) { if( db_is_connected() ) { $t_db_connected = true; } } $t_html_api = false; if( function_exists( 'html_end' ) ) { $t_html_api = true; } # flush any language overrides to return to user's natural default if( $t_db_connected ) { lang_push( lang_get_default() ); $t_lang_pushed = true; } $t_short_file = basename( $p_file ); $t_method_array = config_get_global( 'display_errors' ); if( isset( $t_method_array[$p_type] ) ) { $t_method = $t_method_array[$p_type]; } else { if( isset( $t_method_array[E_ALL] ) ) { $t_method = $t_method_array[E_ALL]; } else { $t_method = 'none'; } } # build an appropriate error string switch( $p_type ) { case E_WARNING: $t_error_type = 'SYSTEM WARNING'; $t_error_description = "'$p_error' in '$p_file' line $p_line"; break; case E_NOTICE: $t_error_type = 'SYSTEM NOTICE'; $t_error_description = "'$p_error' in '$p_file' line $p_line"; break; case E_USER_ERROR: $t_error_type = "APPLICATION ERROR #$p_error"; $t_error_description = error_string( $p_error ); break; case E_USER_WARNING: $t_error_type = "APPLICATION WARNING #$p_error"; $t_error_description = error_string( $p_error ); break; case E_USER_NOTICE: # used for debugging $t_error_type = 'DEBUG'; $t_error_description = $p_error; break; default: # shouldn't happen, just display the error just in case $t_error_type = ''; $t_error_description = $p_error; } $t_error_description = nl2br( $t_error_description ); switch( $t_method ) { case 'halt': # disable any further event callbacks if ( function_exists( 'event_clear_callbacks' ) ) { event_clear_callbacks(); } $t_oblen = ob_get_length(); if( error_handled() && $t_oblen > 0 ) { $t_old_contents = ob_get_contents(); } # We need to ensure compression is off - otherwise the compression headers are output. compress_disable(); # then clean the buffer, leaving output buffering on. if( $t_oblen > 0 ) { ob_clean(); } # don't send the page header information if it has already been sent if( $g_error_send_page_header ) { if( $t_html_api ) { html_page_top1(); if( $p_error != ERROR_DB_QUERY_FAILED && $t_db_connected == true ) { html_page_top2(); } else { html_page_top2a(); } } else { echo '
', $t_error_type, ' |
', $t_error_description, ' |
'; if( null === $g_error_proceed_url ) { echo lang_get( 'error_no_proceed' ); } else { echo '', lang_get( 'proceed' ), ''; } echo ' |
'; error_print_details( $p_file, $p_line, $p_context ); echo ' |
'; error_print_stack_trace(); echo ' |
Previous non-fatal errors occurred. Page contents follow.
'; echo '', $t_error_type, ': ', $t_error_description, '
'; $g_error_handled = true; break; default: # do nothing - note we treat this as we've not handled an error, so any redirects go through. } if( $t_lang_pushed ) { lang_pop(); } $g_error_parameters = array(); $g_error_proceed_url = null; } /** * Print out the error details including context * @param string $p_file * @param int $p_line * @param string $p_context * @return null */ function error_print_details( $p_file, $p_line, $p_context ) { ?>Full path: |
Line: |
Filename | Line | Function | Args | ||
---|---|---|---|---|---|
', ( isset( $t_frame['file'] ) ? htmlentities( $t_frame['file'], ENT_COMPAT, 'UTF-8' ) : '-' ), ' | ', ( isset( $t_frame['line'] ) ? $t_frame['line'] : '-' ), ' | ', ( isset( $t_frame['class'] ) ? $t_frame['class'] : '-' ), ' | ', ( isset( $t_frame['type'] ) ? $t_frame['type'] : '-' ), ' | ', ( isset( $t_frame['function'] ) ? $t_frame['function'] : '-' ), ' | '; $t_args = array(); if( isset( $t_frame['args'] ) && !empty( $t_frame['args'] ) ) { foreach( $t_frame['args'] as $t_value ) { $t_args[] = error_build_parameter_string( $t_value ); } echo '( ', htmlentities( implode( $t_args, ', ' ), ENT_COMPAT, 'UTF-8' ), ' ) | - | '; } } echo '