title: Using inheritance in PHP to add data to array from multiple subclasses
body: <p><strong>Disclaimer:</strong> This is not homework.  Also, I'm describing a simplified situation so bear with my semi-psudo code.</p>
  
  <p>I have what I feel is a pretty standard OOP situation, but I'm not sure the best way to handle it.  Let's say I have 3 classes: <code>Base</code>, <code>A</code>, and <code>B</code>.  Class <code>A</code> extends <code>Base</code> and <code>B</code> extends <code>A</code>.  The <code>Base</code> class's constructor performs a database query that pulls various meta data defined in an array.  See below:</p>
  
  <pre><code>Class Base {
  
      public $meta_data = array('col1','col2');
  
      function __construct() {
          $db-&gt;query("select ".join(',',$this-&gt;meta_data)." from table");
      }
  
  }
  
  Class A extends Base {
  
      public $meta_data = array('col3','col4');
  
      function _construct() {
          parent::__construct();
      }
  
  }
  
  Class B extends A {
  
      public $meta_data = array('col5','col6');
  
      function _construct() {
          parent::__construct();
      }
  
  }
  </code></pre>
  
  <p>When I create a <code>new B()</code> object, I want the Base constructor's sql query to look like this:</p>
  
  <pre><code>select col1, col2, col3, col4, col5, col6 from table;
  </code></pre>
  
  <p>And when I create a <code>new Base()</code> object, I want the sql query to look like this:</p>
  
  <pre><code>select col1, col2 from table;
  </code></pre>
  
  <p>Now...I technically know how to accomplish this (in possibly a crude way) but I'm curious what the proper way is without too much code replication and keeping in mind flexibility for the future (ie, adding a subclass of B).  I basically need to merge the <code>$meta_data</code> arrays on each inheritance level all the way up to the constructor in the <code>Base</code> class.</p>
  
  <p>Any ideas?</p>