gpt4 book ai didi

php - 获取扩展类的文件名

转载 作者:可可西里 更新时间:2023-11-01 12:27:58 24 4
gpt4 key购买 nike

假设我有两个文件,每个文件都有一个类。如何在父类中获取子类所在的文件名?

文件 2(子类):

class B extends A{

}

文件 1:

class A{

final protected function __construct(){
// here I want to get the filename where class B is,
// or whatever class is the child
}

}

最佳答案

不太确定它的用途是什么,但是给你:

class A{

final protected function __construct(){
$obj = new ReflectionClass($this);
$filename = $obj->getFileName();
}

}

关于php - 获取扩展类的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8364246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com