title: spl_autoload_register w/ multiple directories
body: <p>When I execute the following code:</p>
  
  <pre><code>// autoload classes
  spl_autoload_register(function($class) {
      require_once("$class.php");
  });
  </code></pre>
  
  <p>It works for all classes contained in the same directory as the script. However, any classes located in another directory will fail to load. The following solution works:</p>
  
  <pre><code>define('ABSOLUTE_PATH', "/var/www/application");
  
  // autoload classes
  spl_autoload_register(function($class) {
      // class directories
      $dir = array(ABSOLUTE_PATH,
                   ABSOLUTE_PATH . '/models');
  
      foreach($dir as $path) {
          $file = sprintf('%s/%s.php', $path, $class);
          if(is_file($file)) {
              require_once($file);
          }
      }
  });
  </code></pre>
  
  <p>But this feels ugly. I've read that <a href="http://us1.php.net/manual/en/function.spl-autoload-register.php#92514" rel="nofollow">you can use namespaces</a> but I can't seem to get that or anything else to work. Can someone please show me a more elegant solution, if one exists, where I don't have to hard-code the directory paths?</p>