title: Abstract Factories not possible in php < 5.3?
body: <p>I was working on an abstract class to save on some code for a couple of classes. These classes are all factories that instantiate themselves through different static calls. I could save some code by putting all those methods in an abstract class. </p>
  
  <p>However, I ran into a <em>late static binding</em> problem... since our web host isn't using 5.3 or later, I don't have access to get_called_class. If I have </p>
  
  <pre><code>$class = __CLASS__;
  return new $class();
  </code></pre>
  
  <p>in the abstract class, <code>__CLASS__</code> is the name of the abstract class, when I actually want it to use the called class.</p>
  
  <p>I've seen examples of abstract factories on the web where the child classes have their own instantiation methods, and don't rely on the abstract parent for it. However, in this situation, the only reason for the abstract class is to save code, so if I can't do it there, the value of it diminishes greatly. </p>
  
  <p>Is there a workaround in php &lt; 5.3? <code>debug_backtrace()</code>?</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>I did a test and it seems <code>debug_backtrace()</code> will not work! I guess this is why we need <em>late static binding</em>.</p>
  
  <pre><code>&lt;?
  
  abstract class abstractFactory {
      public function create() {
              print_r(debug_backtrace());
              $class = __CLASS__;
              return new $class();
      }
  }
  
  class concreteFactory extends abstractFactory {}
  
  $chimborazo = concreteFactory::create();
  </code></pre>
  
  <p>and the result:</p>
  
  <pre><code>$ php test.php
  Array
  (
      [0] =&gt; Array
          (
              [file] =&gt; /var/www/test.php
              [line] =&gt; 13
              [function] =&gt; create
              [class] =&gt; abstractFactory
              [type] =&gt; ::
              [args] =&gt; Array
                  (
                  )
  
          )
  
  )
  
  Fatal error: Cannot instantiate abstract class abstractFactory in /var/www/test.php on line 7
  </code></pre>