php获取父类文件路径

Tim*_*nen 7 php class parent

index.php //我知道这个文件在哪里

$class = new childclass();
$class->__initComponents();
Run Code Online (Sandbox Code Playgroud)

somefile.php //我知道这个文件在哪里

Class childclass extends parentclass {

}
Run Code Online (Sandbox Code Playgroud)

someparentfile.php //我不知道这个文件在哪里

Class parentclass {
  function __initComponents(){
    //does something
  }
}
Run Code Online (Sandbox Code Playgroud)

我需要找出someparentfile.php的位置.

原因:

我正在调试其他人写的一些困难的PHP代码,我需要找出哪个文件包含定义类参数的代码.

我发现它只要一个类方法调用一个函数来执行此操作:

$class->__initComponents();//the parameter is defined somewhere in there
Run Code Online (Sandbox Code Playgroud)

问题是这个函数在上面的$ class的父类"MyClass"中,我不知道父类在哪里.

有没有办法或一些调试功能,我可以通过它找出这个父类的位置或至少在定义参数的位置?

ps下载整个应用程序然后使用文本搜索将是不合理的.

Kin*_*nch 10

你可以使用Reflection

$object = new ReflectionObject($class);
$method = $object->getMethod('__initComponents');
$declaringClass = $method->getDeclaringClass();
$filename = $declaringClass->getFilename();
Run Code Online (Sandbox Code Playgroud)

有关Reflection-API的更多信息,请参阅手册

但是,为了简单起见,我建议下载源代码并在本地调试它.