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.
I know this is an old question, though it ranks high on Google right now and brought me here while looking for an alternative to reflection. After not finding any, I decided to post a working example for all here.
You can do this by using reflection. Try not to rely on reflection too much since it can be resource-intensive.
For more info on class reflection, see http://www.php.net/manual/en/class.reflectionclass.php
For more info on reflection in general, see http://php.net/reflection
Super old question, but again it's googling well.
You can use
is_subclass_of
:http://php.net/manual/en/function.is-subclass-of.php