title: PHP Autoloader add Namespace path
body: <p>My MVC structure is following:</p>
  
  <pre><code>- web
    -- Classes
      --- Loader.php
    -- Core
      --- Controller.php
      --- Model.php
      --- View.php
      --- Bootstrap.php
      --- DB.php
    -- Project
      --- Controllers (folder)
      --- Models (folder)
      --- Views (folder)
  </code></pre>
  
  <p>Now i have namespaces specified to each. For example i have </p>
  
  <pre><code>    namespace Classes; //for Loader.php
      namespace Core; //For Controller.php, Model.php etc...
      namespace Project\Controllers; //For Controllers inside Controllers folder etc...
  </code></pre>
  
  <p>My autoloader looks like this:</p>
  
  <pre><code>public static function Autoloader2($className) {
      $className = explode('\\', $className);
      $class = array_pop($className);
      $namespace = implode(DIRECTORY_SEPARATOR, $className);
      $file = $namespace . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
  
     require $file;
  }
  </code></pre>
  
  <p>and My main index.php uses </p>
  
  <pre><code>    spl_autoload_register( array('Loader', 'Autoloader2') );
      $app = new Core\Bootstrap();
  </code></pre>
  
  <p>when i open localhost/web/
  i get the following error:</p>
  
  <pre><code>  Warning: require(Core/Project/Controllers/Index.php): failed to open stream: N
  </code></pre>
  
  <p>It seems it prepends Core/ to the requested file. Index.php is inside Project/Controllers and not Core/Project/Controllers. If i try to remove </p>
  
  <pre><code>  //namespace Core; from Bootstrap.php i get the following error
    Fatal error: Class 'Core\Bootstrap' not found 
  </code></pre>
  
  <p>Please help</p>