Jump to content

How can i get name of the child class from parent class?


crezd

Recommended Posts

try

 

<?php

class a {
    public $val;
    
    function __construct() {
        $this->val = 1;
        
    }
    
    function list_children() {
         $classes = get_declared_classes();
         foreach ($classes as $c) {
             if (is_subclass_of($c, 'a')) {
                echo $c,'<br>';
             }
         }
    }
}

class b extends a {
    function __construct() {
        $this->val = 2;
    }
    
}

class c {
    public $val;
}

class d extends a {
    function __construct() {
        $this->val = 3;
    }

}

a::list_children();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.