/**
* Gets the caller of the function where this function is called from
* @param string what to return? (Leave empty to get all, or specify: "class", "function", "line", "class", etc.) - options see: http://php.net/manual/en/function.debug-backtrace.php
*/
function getCaller($what = NULL)
{
$trace = debug_backtrace();
$previousCall = $trace[2]; // 0 is this call, 1 is call in previous function, 2 is caller of that function
if(isset($what))
{
return $previousCall[$what];
}
else
{
return $previousCall;
}
}
public function getCallingFunctionName($completeTrace=false)
{
$trace=debug_backtrace();
if($completeTrace)
{
$str = '';
foreach($trace as $caller)
{
$str .= " -- Called by {$caller['function']}";
if (isset($caller['class']))
$str .= " From Class {$caller['class']}";
}
}
else
{
$caller=$trace[2];
$str = "Called by {$caller['function']}";
if (isset($caller['class']))
$str .= " From Class {$caller['class']}";
}
return $str;
}