title: Dynamically generate classes at runtime in php?
body: <p>Here's what I want to do:</p>
  
  <pre><code>$clsName = substr(md5(rand()),0,10); //generate a random name
  $cls = new $clsName(); //create a new instance
  
  function __autoload($class_name)
  {
    //define that instance dynamically
  }
  </code></pre>
  
  <p>Obviously this isn't what I'm actually doing, but basically I have unknown names for a class and based on the name, I want to generate the class with certain properties etc. </p>
  
  <p>I've tried using eval() but it is giving me fits over private and $this-> references...</p>
  
  <p>//edit</p>
  
  <p>Ok, obviously my short and sweet "here's what I want to do" caused massive strife and consternation amongst those who may be able to provide answers. In the hope of getting an actual answer I'll be more detailed.</p>
  
  <p>I have a validation framework using code hints on the site I maintain. Each function has two definitions</p>
  
  <pre><code>function DoSomething($param, $param2){
     //code
  }
  function DoSomething_Validate(vInteger $param, vFloat $param2){
     //return what to do if validation fails
  }
  </code></pre>
  
  <p>I'm looking to add a validator for primary keys in my database. I don't want to create a separate class for EVERY table (203). So my plan was to do something like</p>
  
  <pre><code>function DoSomething_Validate(vPrimaryKey_Products $id){ }
  </code></pre>
  
  <p>Where the __autoload would generate a subclass of vPrimaryKey and set the table parameter to Products.</p>
  
  <p>Happy now?</p>