[PHP]如何检查一个类是否在不实例化的情况下继承了另一个类? [英] [PHP]How to check if a class inherits another class without instantiating it?
本文介绍了[PHP]如何检查一个类是否在不实例化的情况下继承了另一个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些班级名称. 如何在不实例化的情况下检查一个类是否继承了另一个类?
I have some class name. How to check if a class inherits another class without instantiating it?
if (!class_exists($controller)) //AND I have check type
{
$objectController = new IndexController();
$objectController->index();
}
推荐答案
您必须为此使用反射,这是一个很大的主题:
You'll have to use reflection for that, it's pretty large topic:
http://ca.php.net/manual/fr/book. Reflection.php
稍微看一下文档,尝试一些问题,如果仍然有问题,更精确一些,然后针对该主题发布另一个问题.
Look at the doc a little, try something and if you still have questions, something more precise, then post another question on that topic.
这篇关于[PHP]如何检查一个类是否在不实例化的情况下继承了另一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文