开发者

Retrieving the name of the current function in PHP [duplicate]

开发者 https://www.devze.com 2022-12-17 13:51 出处:网络
This question already has answers here: How do I get the function name inside a function in PHP? 开发者_运维问答(4 answers)
This question already has answers here: How do I get the function name inside a function in PHP? 开发者_运维问答 (4 answers) Closed 8 years ago.

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


Yes, you can get the function's name with the magic constant __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


Maybe via debug_backtrace http://www.php.net/manual/en/function.debug-backtrace.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号