protected function ExceptionController::getLastCaller

Gets the last caller from a backtrace.

The last caller is not necessarily the first item in the backtrace. Rather, it is the first item in the backtrace that is a PHP userspace function, and not one of our debug functions.

Parameters

$backtrace: A standard PHP backtrace.

Return value

An associative array with keys 'file', 'line' and 'function'.

1 call to ExceptionController::getLastCaller()
ExceptionController::decodeException in drupal/core/lib/Drupal/Core/ExceptionController.php
This method is a temporary port of _drupal_decode_exception().

File

drupal/core/lib/Drupal/Core/ExceptionController.php, line 388
Definition of Drupal\Core\ExceptionController.

Class

ExceptionController
This controller handles HTTP errors generated by the routing system.

Namespace

Drupal\Core

Code

protected function getLastCaller($backtrace) {

  // Ignore black listed error handling functions.
  $blacklist = array(
    'debug',
    '_drupal_error_handler',
    '_drupal_exception_handler',
  );

  // Errors that occur inside PHP internal functions do not generate
  // information about file and line.
  while ($backtrace && !isset($backtrace[0]['line']) || isset($backtrace[1]['function']) && in_array($backtrace[1]['function'], $blacklist)) {
    array_shift($backtrace);
  }

  // The first trace is the call itself.
  // It gives us the line and the file of the last call.
  $call = $backtrace[0];

  // The second call give us the function where the call originated.
  if (isset($backtrace[1])) {
    if (isset($backtrace[1]['class'])) {
      $call['function'] = $backtrace[1]['class'] . $backtrace[1]['type'] . $backtrace[1]['function'] . '()';
    }
    else {
      $call['function'] = $backtrace[1]['function'] . '()';
    }
  }
  else {
    $call['function'] = 'main()';
  }
  return $call;
}