public static function Error::getLastCaller

public static Error::getLastCaller(array &$backtrace)

Gets the last caller from a backtrace.

Parameters

array $backtrace: A standard PHP backtrace. Passed by reference.

Return value

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

File

core/lib/Drupal/Core/Utility/Error.php, line 112

Class

Error
Drupal error utility class.

Namespace

Drupal\Core\Utility

Code

public static function getLastCaller(array &$backtrace) {
  // Errors that occur inside PHP internal functions do not generate
  // information about file and line. Ignore black listed functions.
  while (($backtrace && !isset($backtrace[0]['line'])) || 
    (isset($backtrace[1]['function']) && in_array($backtrace[1]['function'], static::$blacklistFunctions))) {
    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 gives 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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Utility!Error.php/function/Error::getLastCaller/8.1.x