You are here

public static function Error::formatBacktrace in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Utility/Error.php \Drupal\Core\Utility\Error::formatBacktrace()

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>.

6 calls to Error::formatBacktrace()
DefaultExceptionSubscriber::onHtml in core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php
Handles any exception as a generic error page for HTML.
Error::renderExceptionSafe in core/lib/Drupal/Core/Utility/Error.php
Renders an exception error message without further exceptions.
ErrorTest::testFormatBacktrace in core/tests/Drupal/Tests/Core/Utility/ErrorTest.php
Tests the formatBacktrace() method.
TestBase::errorHandler in core/modules/simpletest/src/TestBase.php
Handle errors during test runs.
TestBase::exceptionHandler in core/modules/simpletest/src/TestBase.php
Handle exceptions.

... See full list

File

core/lib/Drupal/Core/Utility/Error.php, line 155
Contains \Drupal\Core\Utility\Error.

Class

Error
Drupal error utility class.

Namespace

Drupal\Core\Utility

Code

public static function formatBacktrace(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';
    }
    if (isset($trace['args'])) {
      foreach ($trace['args'] as $arg) {
        if (is_scalar($arg)) {
          $call['args'][] = is_string($arg) ? '\'' . Xss::filter($arg) . '\'' : $arg;
        }
        else {
          $call['args'][] = ucfirst(gettype($arg));
        }
      }
    }
    $return .= $call['function'] . '(' . implode(', ', $call['args']) . ")\n";
  }
  return $return;
}