加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php获取父类文件路径

发布时间:2020-12-13 18:11:19 所属栏目:PHP教程 来源:网络整理
导读:例 index.php //我知道这个文件在哪里 $class = new childclass();$class-__initComponents(); somefile.php //我知道这个文件在哪里 Class childclass extends parentclass {} someparentfile.php //我不知道这个文件在哪里 Class parentclass { function _

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

$class = new childclass();
$class->__initComponents();

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

Class childclass extends parentclass {

}

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

Class parentclass {
  function __initComponents(){
    //does something
  }
}

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

原因:

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

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

$class->__initComponents();//the parameter is defined somewhere in there

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

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

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

你可以使用Reflection
$object = new ReflectionObject($class);
$method = $object->getMethod('__initComponents');
$declaringClass = $method->getDeclaringClass();
$filename = $declaringClass->getFilename();

有关反馈API的更多信息,请参见the manual

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读