是否向PHP类返回子类数组?

是否向PHP类返回子类数组?,php,object,Php,Object,假设我有一门课,比如: class father { function __construct() { $msg = "Blah...\n"; print $msg; } function doSomething() { $msg = get_class($this) . " does something...\n"; print $msg; } } class child extends fat

假设我有一门课,比如:

class father {
    function __construct() {
        $msg = "Blah...\n";
        print $msg;
    }

    function doSomething() {
        $msg = get_class($this) . " does something...\n";
        print $msg;
    }
}
class child extends father {
    function __construct() {
        $this->doSomething()
    }
}
还有一个像这样的儿童班:

class father {
    function __construct() {
        $msg = "Blah...\n";
        print $msg;
    }

    function doSomething() {
        $msg = get_class($this) . " does something...\n";
        print $msg;
    }
}
class child extends father {
    function __construct() {
        $this->doSomething()
    }
}
以及:


是否有方法返回父类的子类的当前实例数组(在本例中为child和elder)?

如果要获取扩展父类的每个类,您应该通过以下方式访问所有声明的类:

并检查结果


编辑:如果您需要了解实例,请迭代
get_defined_vars()
-但为什么您需要了解这一点?

您的意思是是否有办法找到正在使用的子类?我相信这回答了您的问题:不,返回父类所有子类的实例数组。这可能吗?不,不可能,你不需要。@John Tecnicly你可以迭代
get\u defined\u vars()
,检查它们是否是给定类的子类-尽管我不知道它有多有用。