0

let I have a class named A. I have another two classes B and C. Both are extended from the class A. Now I want to get the name of the classes which is extended from class A i.e. B and C.

class A{
}
class B extends A{
}
class C extends A{
}

Now I want to get the name B and C.

I have tried using instanceof

$obj=new B();
if($obj instanceof A)
   echo "derived";

but to do so I have to know the class name.

Scott
  • 1
  • 2

1 Answers1

0
<?php
class A
{

}
class B extends A
{

}
class C extends A
{

}

$b = new B();

if ($b instanceof A) {
    var_dump(get_class($b)); // print B
    var_dump(get_parent_class($b)); // print A
}
yang
  • 183
  • 12