I was wondering if I can get the name of a function from a nested function. I have tried with __FUNCTION__
but the way I am doing it I do not get the expected result, I think it is due to a scope problem. Suppose I have the following:
public function function_1($arguments)
{
if (is_array($arguments)) {
return array_map(function ($argument) {
// Here I would like __FUNCTION__ to return the string functon_1
// to refer to the name of the parent function.
return call_user_func_array([$this, __FUNCTION__], [$argument]);
}, $arguments);
}
return $arguments;
}
Thank you very much in advance for any help you can give me.
EDIT 1
For now I have managed to get the expected result as follows:
public function function_1($arguments)
{
$callback = __FUNCTION__;
if (is_array($arguments)) {
return array_map(function ($argument) use ($callback) {
// Here I would like __FUNCTION__ to return the string functon_1
// to refer to the name of the parent function.
return call_user_func_array([$this, $callback], [$argument]);
}, $arguments);
}
return $arguments;
}