Php 查找子类中的哪个方法调用基类中的方法

Php 查找子类中的哪个方法调用基类中的方法,php,reflection,Php,Reflection,我试图从基类中调用我的方法的子类中获取方法的名称。我怎样才能得到这个 class MyBaseClass { protected static function mybasemethod() { // how can I get the name of the method that called this? // I'm looking for 'myothermethod' } } class MyClassA extends MyBase

我试图从基类中调用我的方法的子类中获取方法的名称。我怎样才能得到这个

class MyBaseClass {
    protected static function mybasemethod() {
        // how can I get the name of the method that called this?
        // I'm looking for 'myothermethod'
    }
}


class MyClassA extends MyBaseClass {
   protected static function myothermethod() {
       self::mybasemethod();
   }
}

要获取类的名称,可以尝试函数get\u class\u methods()


感谢您为今天的学习机会提供了灵感。我经常无所事事地想知道这是否可以做到,但从未费心去调查。现在,我知道这确实是可以做到的

我在当前正在测试的例程中测试了以下代码片段

System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace ( false );
System.Diagnostics.StackFrame frame = trace.GetFrame ( 1 );
Console.WriteLine ( "Calling method = {0}" , frame.GetMethod ( ).Name );
输出如下

Calling method = UtilsExercises
UtilsExercises
是调用我嵌入代码的例程的方法的名称


前面的示例是对StackTrace类文档中所示示例的改编。

您需要子类中方法的名称,对吗?可能重复是的,我正在尝试获取有关基类中调用方法的唯一信息(出于缓存目的,我将使用它作为缓存键的一部分)。因此,在基类方法中,我想获得调用它的子类中方法的名称,因此在这种情况下,它将是“myothermethod”。建议您的示例中有一些输入错误。您将查找“myothermethod”而不是“mybasemethod”,以及
myothermethod()
将调用
self::mymethod
而不是
mybasemethod()
?谢谢,但我使用的是phpun直到你提到我的注意,我没有注意到这个例子是php,它说明了它的语法与C#、Perl、PowerShell等的语法有多相似。
Calling method = UtilsExercises