This question already has an answer here:
这个问题在这里已有答案:
- How do I get the function name inside a function in PHP? 4 answers
- 如何在PHP中的函数内获取函数名称? 4个答案
Is there a function that can return the name of the current function a program is executing?
是否有一个函数可以返回程序正在执行的当前函数的名称?
2 个解决方案
#1
122
Yes, you can get the function's name with the magic constant __FUNCTION__
是的,您可以使用魔法常量__FUNCTION__获取函数的名称
class foo
{
function print_func()
{
echo __FUNCTION__;
}
function print_method()
{
echo __METHOD__;
}
}
$obj = new foo();
$obj->print_func(); // Returns: print_func
$obj->print_method(); // Returns: foo::print_method
#2
10
Maybe via debug_backtrace http://www.php.net/manual/en/function.debug-backtrace.php
也许通过debug_backtrace http://www.php.net/manual/en/function.debug-backtrace.php
#1
122
Yes, you can get the function's name with the magic constant __FUNCTION__
是的,您可以使用魔法常量__FUNCTION__获取函数的名称
class foo
{
function print_func()
{
echo __FUNCTION__;
}
function print_method()
{
echo __METHOD__;
}
}
$obj = new foo();
$obj->print_func(); // Returns: print_func
$obj->print_method(); // Returns: foo::print_method
#2
10
Maybe via debug_backtrace http://www.php.net/manual/en/function.debug-backtrace.php
也许通过debug_backtrace http://www.php.net/manual/en/function.debug-backtrace.php