title: Dynamically create PHP object based on string
body: <p>I would like to create an object in PHP based on a type defined by a string in a MySQL database. The database table has columns and sample data of:</p>
  
  <pre class="lang-none prettyprint-override"><code> id | type | propertyVal
  ----+------+-------------
    1 | foo  | lorum
    2 | bar  | ipsum
  </code></pre>
  
  <p>...with PHP data types</p>
  
  <pre><code>class ParentClass {...}
  class Foo extends ParentClass {private $id, $propertyVal; ...}
  class Bar extends ParentClass {private $id, $propertyVal; ...} 
  //...(more classes)...
  </code></pre>
  
  <p>Using only one query, I would like to SELECT a row by id and create an object of the type define the table's type column with other columns in the SELECTed row being assigned to the newly created object.</p>
  
  <p>I was thinking that using: </p>
  
  <ol>
  <li><code>mysql_fetch_object()</code></li>
  <li>Reading the type attribute</li>
  <li>Creating an object with type defined by type attribute</li>
  </ol>
  
  <p>But know of no way to dynamically create a type based on a string. How does one do this? </p>