You are here

function _mailhandler_get_last_caller in Mailhandler 6

Return last caller of a backtrace. Used to trac calls to deprecated functions of this module.

Parameters

$backtrace:

Return value

string caller

Related topics

2 calls to _mailhandler_get_last_caller()
mailhandler_watchdog_deprecated in ./mailhandler.module
Record deprecated function usages using watchdog.
mailhandler_watchdog_record in ./mailhandler.module
Log a Mailhandler message.

File

./mailhandler.module, line 1403
Mailhandler module code.

Code

function _mailhandler_get_last_caller($backtrace) {

  // Errors that occur inside PHP internal functions do not generate
  // information about file and line. Ignore black listed functions.
  $blacklist = array(
    'debug',
  );
  while ($backtrace && !isset($backtrace[1]['line']) || isset($backtrace[2]['function']) && in_array($backtrace[2]['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[1];

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