title: Possible to use spl_autoload_register from object?
body: <p>Simple question but I don't know if this is really possible..</p>
  
  <p>Example:</p>
  
  <p>class test has a spl_autoload_register like this:</p>
  
  <pre><code>function __construct() {
  spl_autoload_register(function ($class) {
          echo "{$this-&gt;projectroot}/include/{$class}.php";
          require_once(strtolower("{$this-&gt;projectroot}/classes/{$class}.php"));
  });
  }
  </code></pre>
  
  <p>$projectroot is an object scope variable with the path to the project's directory.</p>
  
  <p>I include class test in my project, create a new instance out of it:</p>
  
  <pre><code>$test = new test();
  </code></pre>
  
  <p>Now I want $test to load a class file with functions when I create:</p>
  
  <pre><code>$test2 = new test2();
  </code></pre>
  
  <p>where test2 is the class in /include/test2.php called test2.</p>
  
  <p>when I try to do this, it gives me an error saying:</p>
  
  <pre><code>Fatal error: Using $this when not in object context in
  </code></pre>
  
  <p>but when I try:</p>
  
  <pre><code>$test2 = new $test1-&gt;test2();
  </code></pre>
  
  <p>it ignores the spl_autoload_register function in test1 completely :/ just stating that obviously test2 isn't a known method (undefined property).</p>
  
  <p>Is there a way to use the spl_autoload_register function in class test in my project without further defining it in my main project?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I "fixed" it using a global variable, but I am curious if there's some OOP method? (Not that this is practical/best practise OOP use...) just curious.</p>