[英]get function name from extended class php
Hi I do not speak English (google translator) apologize for the translation, I want to do something like this: 嗨,我不会说英语(谷歌翻译)对此翻译表示歉意,我想这样做:
class First_class extends Second_class
{
function first_class_function ()
{
echo $this->second_class_function ();
}
}
class Second_class
{
function second_class_function ()
{
return "function name which call this function" // in this case first_class_function
}
}
Is that possible? 那可能吗?
Yes this is possible, use the constant variable __FUNCTION__
or __METHOD__
, this will give you the function name that you used, as you are using a class I'd recommend using the METHOD constant. 是的,这是可能的,使用常量变量__FUNCTION__
或__METHOD__
,这将为您提供所使用的函数名,因为您正在使用我建议使用METHOD常量的类。
function second_class_function () {
return __METHOD__;
}
您可以使用debug_backtrace函数: http ://php.net/manual/en/function.debug-backtrace.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.