PHP-每类配置管理器和继承
我有一个类PHP-每类配置管理器和继承,php,dependency-injection,multiple-inheritance,Php,Dependency Injection,Multiple Inheritance,我有一个类Injector,它使用get\u class($this)使用Injector获取类,从db或文件加载类中的一些数据。。。它非常适合于像类用户扩展注入器这样的简单继承 问题是:如果一个类SpecialUser扩展了User,get\u class只返回SpecialUser,User将不会填充所需的数据。是否有更好的解决方案,然后使用get_parent_class()循环trouth类 谢谢您可以使用以下功能: $names = array(); if ($this instan
Injector
,它使用get\u class($this)
使用Injector获取类,从db或文件加载类中的一些数据。。。它非常适合于像类用户扩展注入器这样的简单继承
问题是:如果一个类SpecialUser
扩展了User
,get\u class
只返回SpecialUser
,User
将不会填充所需的数据。是否有更好的解决方案,然后使用get_parent_class()循环trouth类
谢谢您可以使用以下功能:
$names = array();
if ($this instanceof Injector) {
$class = get_class($this);
do {
$names[] = $class;
$class = get_parent_class($class);
} while ($class !== 'Injector');
}
.嗨,欢迎来到stackoverflow!请阅读