title: Define a class dynamically?
body: <p>Is there a way to dynamically and conditionally create a class definition in PHP, i.e.</p>
  
  <pre><code>if (condition matches)
    include file containing class definition
  else
    class myclass extends ancestor_class { .................... }
  </code></pre>
  
  <p>without <code>eval()</code>? </p>
  
  <p>My background is the accepted answer to <a href="https://stackoverflow.com/questions/2425057/having-the-option-of-customized-classes-but-a-unified-class-name">this question</a>. I am looking for the best way to build a untouchable core library, with user-defined empty classes extending the core library if necessary.</p>
  
  <p>I want to create the final class definition "on the fly" if there is no user-defined empty class for a certain ancestor class.</p>
  
  <p>Including another include file (containing the empty class definition) is out of the question, as there will be quite a number of classes.</p>
  
  <blockquote>
    <p><strong>Update:</strong> This seems to be possible in a normal condition block - didn't think of that. However, according to <a href="http://www.sitepoint.com/blogs/2004/03/31/conditional-class-declaration-bad-practice/" rel="nofollow noreferrer">this article</a>, it also seems to be regarded as bad practice and may be removed in the future. Hmm. Creative ideas welcome.</p>
  </blockquote>