示例
index.php//我知道这个文件在哪里
$class = new childclass();
$class->__initComponents();
somefile.php//我知道这个文件在哪里
Class childclass extends parentclass {
}
someparentfile.php//我不知道这个文件在哪里
Class parentclass {
function __initComponents(){
//does something
}
}
我需要找出某人的父文件.php在哪里。
原因:
我正在调试其他人编写的一些困难的php代码,我需要找出哪个文件包含定义类参数的代码。
我发现它就像一个调用这样做的函数的类方法一样:
$class->__initComponents();//the parameter is defined somewhere in there
问题是这个函数在上述$class的父类"MyClass"中,我不知道父类在哪里。
有没有办法或一些调试函数来找出这个父类的位置或至少定义参数的位置?
附言下载整个应用程序,然后使用文本搜索是不合理的。
您可以使用
反射
$object = new ReflectionObject($class);
$method = $object->getMethod('__initComponents');
$declaringClass = $method->getDeclaringClass();
$filename = $declaringClass->getFilename();
有关更多信息,Reflection-API 可以实现什么,请参阅手册
但是,为了简单起见,我建议下载源代码并在本地调试。
$object = new ReflectionObject($this); // Replace $this with object of any class.
echo 'Parent Class Name: <br>';
echo $object->getParentClass()->getName();
echo '<br>Parent Class Location: <br>';
echo $object->getParentClass()->getFileName();