function format_backtrace

Formats a backtrace into a plain-text string.

The calls show values for scalar arguments and type names for complex ones.

Parameters

array $backtrace: A standard PHP backtrace.

Return value

string A plain-text line-wrapped string ready to be put inside <pre>.

3 calls to format_backtrace()
TestBase::errorHandler in drupal/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
Handle errors during test runs.
TestBase::exceptionHandler in drupal/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
Handle exceptions.
_drupal_log_error in drupal/core/includes/errors.inc
Logs a PHP error or exception and displays an error page in fatal cases.

File

drupal/core/includes/errors.inc, line 337
Functions for error handling.

Code

function format_backtrace(array $backtrace) {
  $return = '';
  foreach ($backtrace as $trace) {
    $call = array(
      'function' => '',
      'args' => array(),
    );
    if (isset($trace['class'])) {
      $call['function'] = $trace['class'] . $trace['type'] . $trace['function'];
    }
    elseif (isset($trace['function'])) {
      $call['function'] = $trace['function'];
    }
    else {
      $call['function'] = 'main';
    }
    foreach ($trace['args'] as $arg) {
      if (is_scalar($arg)) {
        $call['args'][] = is_string($arg) ? '\'' . filter_xss($arg) . '\'' : $arg;
      }
      else {
        $call['args'][] = ucfirst(gettype($arg));
      }
    }
    $return .= $call['function'] . '(' . implode(', ', $call['args']) . ")\n";
  }
  return $return;
}