WordPress.org

Make WordPress Core

Opened 19 months ago

Last modified 19 months ago

#22117 new enhancement

Better backtrace

Reported by: msolution Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.4.2
Component: Database Keywords: 2nd-opinion has-patch
Focuses: Cc:

Description

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;
}

Attachments (1)

22117.patch (1.5 KB) - added by msolution 19 months ago.

Download all attachments as: .zip

Change History (4)

comment:1 follow-up: scribu19 months ago

Related: #19589

It would be nice if you could submit your addition in patch form: http://core.trac.wordpress.org/wiki#HowtoSubmitPatches

comment:2 in reply to: ↑ 1 msolution19 months ago

Replying to scribu:

sorry new around here, will look into the link :)

msolution19 months ago

comment:3 scribu19 months ago

  • Keywords has-patch added; dev-feedback removed
Note: See TracTickets for help on using tickets.