在PHP中检索当前函数的名称 [英] Retrieving the name of the current function in PHP
问题描述
是否有一个函数可以返回程序正在执行的当前函数的名称?
是的,您可以使用魔术常量获取函数的名称 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
这篇关于在PHP中检索当前函数的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! __ FUNCTION __
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b {
echo __FUNCTION__;
}
函数print_method()
{
echo __METHOD__;
}
}
$ obj = new foo();
$ obj-> print_func(); //返回:print_func
$ obj-> print_method(); //返回:foo :: print_method
__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