title: How to use spl_autoload_register for multiple diectories in PHP?
body: <p>I'm actually trying to create a MVC framework for my own, however I'm having troubles with the Autoload. It's not a problem actually, but I'd like to ask the gurus, how are they using the <code>spl_autoload_register</code> function when there are different directories.</p>
  
  <p>Lets say we have the following directories:</p>
  
  <pre><code>Controllers
  Libs
  Models
  </code></pre>
  
  <p>Each folder contains different classes, like:</p>
  
  <pre><code>Controllers:
     Main.php
     File.php
     About.php
  Libs:
     Main.php
     Front_controller.php
  Models:
     Index.php
     File.php
     Login.php
  </code></pre>
  
  <p>You can notice that some file names might be found with the same name in different directories. Okay, so this is what I've tried so far:</p>
  
  <pre><code>spl_autoload_register(function ($class) { 
  
      $pathContorllers = 'Controllers/' . $class . '.php';
      $pathLibs = 'Libs/' . $class . '.php';
      $pathModels = 'Models/' . $class . '.php';
  
      if (file_exists($pathContorllers)) {
          require_once $pathContorllers;
      } elseif (file_exists($pathLibs)) {
          require_once $pathLibs;
      } elseif (file_exists($pathModels )) {
          require_once $pathModels ;
      }
  });
  </code></pre>
  
  <p>It is working well, however I'm sure that there is another way to make everything simpler. Can anyone suggest me how can I make this code better or simpler / what are gurus using in this situation?</p>