This has been asked before: How can I get the callee in PHP?
You can get the information you need with debug_backtace. Here is a very clean function I have found:
<?php
/**
* 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 get_caller($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;
}
}
And you (might) use it like this:
<?php
function foo($full)
{
if ($full) {
return var_export(get_caller(), true);
} else {
return 'foo called from ' . get_caller('function') . PHP_EOL;
}
}
function bar($full = false)
{
return foo($full);
}
echo bar();
echo PHP_EOL;
echo bar(true);
Which returns:
foo called from bar
array (
'file' => '/var/www/sentinel/caller.php',
'line' => 31,
'function' => 'bar',
'args' =>
array (
0 => true,
),
)