[wp-trac] [WordPress Trac] #22117: Better backtrace

WordPress Trac wp-trac at lists.automattic.com
Sat Oct 6 14:06:50 UTC 2012


#22117: Better backtrace
--------------------------------------+-------------------------
 Reporter:  msolution                 |       Type:  enhancement
   Status:  new                       |   Priority:  normal
Milestone:  Awaiting Review           |  Component:  Database
  Version:  3.4.2                     |   Severity:  normal
 Keywords:  2nd-opinion dev-feedback  |
--------------------------------------+-------------------------
 Hey,
 This is a small hack for a prettier backtrace info.

 the file '''''/wp-includes/functions.php''''' at Line 3547

 the new functions with added lines

 {{{
 function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames =
 0, $pretty = true ) {
         if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) )
                 $trace = debug_backtrace( false );
         else
                 $trace = debug_backtrace();

         $caller = array();
         $check_class = ! is_null( $ignore_class );
         $skip_frames++; // skip this function
         $last_info = array();

         foreach ( $trace as $call ) {
                 if ( isset( $call['class'] ) && 'wpdb' == $call['class'] )
                 {
                         $last_info['file'] = basename($call['file']);
                         $last_info['line'] = $call['line'];
                 }

                 if ( $skip_frames > 0 ) {
                         $skip_frames--;
                 } elseif ( isset( $call['class'] ) ) {
                         if ( $check_class && $ignore_class ==
 $call['class'] )
                                 continue; // Filter out calls
                         $caller[] =
 "{$call['class']}{$call['type']}{$call['function']}";
                         if( empty( $last_info['func'] ) )
 $last_info['func'] = $call['class'].'->'.$call['function'];
                 } else {
                         if ( in_array( $call['function'], array(
 'do_action', 'apply_filters' ) ) ) {
                                 $caller[] =
 "{$call['function']}('{$call['args'][0]}')";
                         } elseif ( in_array( $call['function'], array(
 'include', 'include_once', 'require', 'require_once' ) ) ) {
                                 $caller[] = $call['function'] . "('" .
 str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) .
 "')";
                         } else {
                                 $caller[] = $call['function'];
                                 if( empty( $last_info['func'] ) )
 $last_info['func'] = $call['function'];
                         }
                 }
         }
         if ( $pretty )
                 return sprintf(__("Error at %s, at line %d, in function
 %s<br/>%s"),
                                 $last_info['file'], $last_info['line'],
 $last_info['func'], join( ', ', array_reverse( $caller ) ) );
         else
                 return $caller;
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22117>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list