title: Instantiate new object from variable
body: <p>I'm using the following class to autoload all my classes. This class extends the core class.</p>
  
  <pre><code>class classAutoloader extends SH_Core {
  
       public function __construct() {
          spl_autoload_register(array($this, 'loader'));      
       }
  
       private function loader($class_name) {
          $class_name_plain = strtolower(str_replace("SH_", "", $class_name));
          include $class_name_plain . '.php';
       }
  }
  </code></pre>
  
  <p>I instantiate that class in the <code>__construct()</code> of my core class:</p>
  
  <pre><code>public function __construct() {
      $autoloader = new classAutoloader();
  }
  </code></pre>
  
  <p>Now I want to be able to instantiate objects in the loader class like this:</p>
  
  <pre><code>private function loader($class_name) {
      $class_name_plain = strtolower(str_replace("SH_", "", $class_name));
      include $class_name_plain . '.php';
      $this-&gt;$class_name_plain = new $class_name;
  }
  </code></pre>
  
  <p>But I get the following error calling <code>$core-template</code> like this:</p>
  
  <pre><code>require 'includes/classes/core.php';
  $core = new SH_Core();
  
  if (isset($_GET['p']) &amp;&amp; !empty($_GET['p'])) {
      $core-&gt;template-&gt;loadPage($_GET['p']);
  } else {
      $core-&gt;template-&gt;loadPage(FRONTPAGE);   
  }
  </code></pre>
  
  <p>The error:</p>
  
  <blockquote>
    <p>Notice: Undefined property: SH_Core::$template in /home/fabian/domains/fabianpas.nl/public_html/framework/index.php on line 8<br>
    Fatal error: Call to a member function loadPage() on a non-object in /home/fabian/domains/fabianpas.nl/public_html/framework/index.php on line 8</p>
  </blockquote>
  
  <p>It autoloads the classes but just doesn't initiate the object because using the following code it works without any problems:</p>
  
  <pre><code>public function __construct() {
      $autoloader = new classAutoloader();
  
      $this-&gt;database = new SH_Database();
      $this-&gt;template = new SH_Template();
      $this-&gt;session = new SH_Session();
  }
  </code></pre>