title: PHP Pass Instance Of Object To Abstract Class Constructor
body: <p>in an effort to further my understanding of OOP, I've decided to refactor some of my code using an abstract class. The idea is roughly;</p>
  
  <ul>
  <li>One "parent" abstract class which forms a base for all child classs' to extend.</li>
  <li>One "helper" class which has a series of methods which children of the abstract class will need.</li>
  <li>the "helper" class will be used by other classes, so I don't want this to be an integral part of the abstract class. </li>
  </ul>
  
  <p>The problem;</p>
  
  <p>The child class extends the abstract class as intended, but PHP gives me a warning that the <code>$helper</code> argument is missing from the abstract class's constructor. I believe the constructor is being called because there isn't one in my child class, which is fine, but since you don't directly call an abstract class, how do I get this to work? Sample code below;</p>
  
  <pre><code>abstract class Parent_Abstract
  {
      public $input_helper_methods;
  
      public function __construct( $helpers = NULL )
      {
  
          //set the helper methods
          $this-&gt;input_helper_methods = $helpers;
  
      }
  }
  </code></pre>
  
  <p>The variable <code>$helpers</code> is in another file at the moment, which is included at the top of the file with the abstract class. Again, I think there's an issue with how this is being done. When I understand the structure I would like to use an autoloader, but for now, just manual would be good. This is the contents of that file;</p>
  
  <pre><code>class RD_Form_Input_Helper_Methods
  {
      private $var = 'something';
  }
  
  $helpers = new RD_Form_Input_Helper_Methods;
  </code></pre>
  
  <p>I hope this makes some sense. Thanks for taking the time to read/reply. </p>
  
  <p>Another example;</p>
  
  <pre><code>//"helper" classes. I would like these methods to be available to Child_One and Child_Two
  class Helper_Functions {}
  
  class Formatting_Functions {}
  
  
  abstract class Parent_Abstract()
  {
      private $helper_functions;
      private $formatting_functions;
  
      public function __construct( $object_one, object_two )
      {
          $this-&gt;helper_functions = $object_one;
          $this-&gt;helper_functions = $object_two;
      }
  
  }
  
  class Child_One extends Parent_Abstract 
  {
      //I can use any of the properties or methods from the Helper_Functions or Formatting_Function class
  }
  
  class Child_Two extends Parent_Abstract 
  {
      //I can use any of the properties or methods from the Helper_Functions or Formatting_Function class
  }
  </code></pre>