title: PHP Autoloading with SplClassLoader?
body: <p>I'm learning about namespaces in PHP 5.3 and I would like to use Namespaces Autoloading. I found this <a href="https://gist.github.com/221634">SplClassLoader class</a>, but I can't figure out how it works.</p>
  
  <p>Let's say I have directory structure like this:</p>
  
  <pre><code>system
    - framework
      - http
        - request.php
        - response.php
  index.php
  SplClassLoader.php
  </code></pre>
  
  <p>How do I enable class autoloading? What namespaces should <code>request.php</code> and <code>response.php</code> have? </p>
  
  <p>This is the <code>request.php</code>:</p>
  
  <pre><code>namespace framework\http;
  
  class Request
  {
      public function __construct()
      {
          echo __CLASS__ . " constructer!";
      }
  } 
  </code></pre>
  
  <p>And this is the <code>response.php</code>:</p>
  
  <pre><code>namespace framework\http;
  
  class Request
  {            
      public function __construct()
      {      
          echo __CLASS__ . " constructed!";                
      }           
  }   
  </code></pre>
  
  <p>And in <code>index.php</code> I have:</p>
  
  <pre><code>require_once("SplClassLoader.php");
  $loader = new SplClassLoader('framework\http', 'system/framework');
  $loader-&gt;register();
  
  $r = new Request();
  </code></pre>
  
  <p>I get this error message:</p>
  
  <pre><code>Fatal error: Class 'Request' not found in C:\wamp\apache\htdocs\php_autoloading\index.php on line 8
  </code></pre>
  
  <p>Why is this not working? How can I use <code>SplClassLoader</code> in my projects so it loads/requires my classes, and how should I setup and name folders and namespaces?</p>