title: PHP OOP: Get all declared classes which are have extended another parent class
body: <p>I need to get all declared classes which are have extended another parent class.</p>
  
  <p>So for example...</p>
  
  <pre><code>class ParentClass {
  
  }
  
  class ChildOne extends ParentClass {
  
  }
  
  class ChildTwo extends ParentClass {
  
  }
  
  class ChildThree {
  
  }
  </code></pre>
  
  <p>I need an array that outputs this:</p>
  
  <pre><code>array('ChildOne', 'ChildTwo')
  </code></pre>
  
  <p>I'm new to PHP OOP, but based on some Googling, I came up with this solution.</p>
  
  <pre><code>$classes = array();
  
  foreach( get_declared_classes() as $class ) {
      if ( is_subclass_of($class, 'ParentClass') ){
          array_push($classes, $class);
      }
  }
  </code></pre>
  
  <p>What I want to ask is whether this is the best practice to do what I want to do, or is there a better way? The global scope will contain a lot of other classes that isn't a child of <code>ParentClass</code>. Is looping through all declared classes the best way to go?</p>
  
  <p><strong>EDIT</strong> <em>(clarification of purpose)</em>:</p>
  
  <p>What I want to achieve with this is to instantiate each child class extending the parent class.</p>
  
  <p>I want to do <code>$childone = new ChildOne; $childtwo = new ChildTwo;</code> for every child of <code>ParentClass</code>.</p>