【问题标题】:get function name from extended class php从扩展类 php 中获取函数名
【发布时间】:2015-04-06 19:08:48
【问题描述】:

您好,我不会说英语(谷歌翻译)为翻译道歉,我想做这样的事情:

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
   }
}

这可能吗?

【问题讨论】:

  • 你测试了吗?!?

标签: php function class extends


【解决方案1】:

您可以使用 debug_backtrace 函数:http://php.net/manual/en/function.debug-backtrace.php

【讨论】:

    【解决方案2】:

    是的,这是可能的,使用常量变量 __FUNCTION__ 或 __METHOD__,这将为您提供您使用的函数名称,因为您正在使用我建议使用 METHOD 常量的类。

    function second_class_function () {
        return __METHOD__;
    }
    

    【讨论】:

    • 但是返回 "second_function..." 我需要显示 "first function..." 比如返回第一个函数的名称?,我想像 self :: METHOD 或 static::__METHOD__ 但不起作用 u.u
    猜你喜欢
    • 1970-01-01
    • 2011-08-27
    • 2019-09-24
    • 2018-06-18
    • 1970-01-01
    • 2018-01-14
    • 1970-01-01
    • 2010-10-05
    相关资源
    最近更新 更多