简体   繁体   中英

How to get the name of the classes which extends a specific class in php

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 ie 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.

<?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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM