title: Replace PHP __autoload (deprecated method) to spl_autoload_register
body: <p>How can I change this code to use new <code>spl_autoload_register</code> function instead the   deprecated method <code>__autoload</code>?</p>
  
  <p><strong>My code(works properly):</strong></p>
  
  <pre><code>&lt;?php
  require_once(ROOT.DS.'config'.DS.'config.php');
  
  function __autoload($class_name) {
      $lib_path = ROOT.DS.'lib'.DS.strtolower($class_name).'.class.php';
      $controller_path = ROOT.DS.'controller'.DS.str_replace('controller', '', strtolower($class_name)).'.controller.php';
      $model_path = ROOT.DS.'models'.DS.strtolower($class_name).'.php';
  
      if (file_exists($lib_path)){
          require_once($lib_path);
      }elseif (file_exists($controller_path)){
          require_once($controller_path);
      }elseif (file_exists($model_path)){
          require_once($model_path);
      }else {
          throw new Exception("failed to include class named:".$class_name);
      }
  
  }
  </code></pre>
  
  <p><strong>I tried to change it to:</strong></p>
  
  <pre><code>&lt;?php
  require_once(ROOT.DS.'config'.DS.'config.php');
  spl_autoload_register(function ($class_name) {
      $lib_path = ROOT.DS.'lib'.DS.strtolower($class_name).'.class.php';
      $controller_path = ROOT.DS.'controller'.DS.str_replace('controller', '', strtolower($class_name)).'.controller.php';
      $model_path = ROOT.DS.'models'.DS.strtolower($class_name).'.php';
  
      if (file_exists($lib_path)){
          require_once($lib_path);
      }elseif (file_exists($controller_path)){
          require_once($controller_path);
      }elseif (file_exists($model_path)){
          require_once($model_path);
      }else {
          throw new Exception("failed to include class named:".$class_name);
      }
  
  });
  </code></pre>
  
  <p>But I'm getting an error: </p>
  
  <blockquote>
  Fatal error: Uncaught Error: Class 'Config' not found in /srv/http/mvc/config/config.php:3 Stack trace: #0 /srv/http/mvc/lib/init.php(2): require_once() #1 /srv/http/mvc/webroot/index.php(6): require_once('/srv/http/mvc/l...') #2 {main} thrown in /srv/http/mvc/config/config.php on line 3
  </blockquote>