在PHP中检索当前函数的名称[重复]

时间:2023-01-26 21:24:52

This question already has an answer here:

这个问题在这里已有答案:

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