class A {}
class B {}
class C extends B {}
$obj=new ReflectionClass('C');
var_dump($obj->isSubclassOf ('A')); //boolean false
var_dump($obj->isSubclassOf ('B')); //boolean true
(PHP 5, PHP 7)
ReflectionClass::isSubclassOf — Checks if a subclass
$class
)Checks if the class is a subclass of a specified class or implements a specified interface.
class
The class name being checked against.
성공 시 TRUE
를, 실패 시 FALSE
를 반환합니다.
class A {}
class B {}
class C extends B {}
$obj=new ReflectionClass('C');
var_dump($obj->isSubclassOf ('A')); //boolean false
var_dump($obj->isSubclassOf ('B')); //boolean true
Note, that this method is a bit different than the `instanceof` operator, which returns true, when it is a subclass or the very same class (interface). Here, only being a subclass results in true, eg.
class A {}
class B extends A {}
$a = new ReflectionClass('A');
$AA = new A;
$b = new ReflectionClass('B');
$BB = new B;
var_dump($a->isSubclassOf($b)); // false
var_dump($AA instanceof $BB); // false
var_dump($b->isSubclassOf($a)); // true
var_dump($BB instanceof $AA); // true
var_dump($a->isSubclassOf($a)); // false
var_dump($AA instanceof $AA); // true