在 PHP 中检索当前函数的名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2115913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:05:55  来源:igfitidea点击:

Retrieving the name of the current function in PHP

phpfunction

提问by Cian E

Is there a function that can return the name of the current function a program is executing?

是否有一个函数可以返回程序正在执行的当前函数的名称?

回答by Sarfraz

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