title: php: Instantiate class on-the-fly
body: <p>Is it possible to instantiate a class from a string, without declaring another variable before ?</p>
  
  <p>It's usually done writing </p>
  
  <pre><code>$className = 'myClass'
  $instance  = new $className();
  </code></pre>
  
  <p>but it could be handy to have it shorter like for example</p>
  
  <pre><code>$instance  = new ${'className'}();
  </code></pre>
  
  <p>The purpose is to have objects created (under condition) inside a loop without use of extra vars...</p>
  
  <p><strong>Edit :</strong> $className is dynamic, it is hard coded above to explain the situation</p>