Is there a way in PHP to know if one class inherits another?
class Controller
{
}
class HomeController extends Controller
{
}
class Dummy
{
}
// What I would like to do
$result = class_extends('HomeController', 'Controller'); /// true
$result = class_extends('Dummy', 'Controller'); /// false
You need to use instanceof.
Note that
implementsis incorrect.instanceofshould be used in both cases (checking whether an object is an inherited class, or whether the object implements an interface).Example from manual:
gives: