在PHP中检索当前函数的名称 [英] Retrieving the name of the current function in PHP

查看:82
本文介绍了在PHP中检索当前函数的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

是的,您可以使用魔术常量获取函数的名称 __ FUNCTION __

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b {
echo __FUNCTION__;
}
函数print_method()
{
echo __METHOD__;
}
}

$ obj = new foo();
$ obj-> print_func(); //返回:print_func
$ obj-> print_method(); //返回:foo :: print_method


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

这篇关于在PHP中检索当前函数的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆