Cotonti / Open Source PHP Content Management FrameworkContent Management Framework

Pastebin / testing_backtrace()

/**
 * Generates a fancy backtrace and returns it as string.
 * @param  int    $limit Number of recent calls to show.
 * @return string        Backtrace as HTML list
 */
function testing_backtrace($limit = 0)
{
	$html = cot_rc('testing_backtrace_begin');

	$bt = debug_backtrace();

	$num = 0;
	foreach ($bt as $call)
	{
		// Skip special funcs
		if (in_array($call['function'], array('testing_backtrace')))
		{
			continue;
		}

		// Preformat function name
		$args = implode(', ', $call['args']);
		switch ($call['type'])
		{
			case '::':
				$name = $call['class'] . $call['type'] . $call['function'];
				break;
			case '->':
				$name = $call['object'] . $call['type'] . $call['function'];
				break;
			default:
				$name = $call['function'];
		}

		$html .= cot_rc('testing_backtrace_item', array(
			'name' => $name,
			'args' => $args,
			'file' => $call['file'],
			'line' => $call['line']
		));

		$num++;
		if ($limit > 0 && $num == $limit)
		{
			break;
		}
	}

	$html .= cot_rc('testing_backtrace_end');
	return $html;
}

Tags:

No tags