title: How to call __autoload() in php code
body: <p>I am new to php and I want to use php5's __autoload functionality in my code. I wrote below code in my index.php but I don't understand how and when I should call __autoload function. </p>
  
  <pre><code>function __autoload($class) {
      if (file_exists($class . '.php')) {
          include($class . '.php');
      } else {
          throw new Exception('Unable to load class named $class');
      }
  }
  </code></pre>
  
  <p>I have seen <a href="https://stackoverflow.com/questions/7753269/how-will-this-autoload-function">this thread</a> also but I do not have such autoloader class in my application. Do every application need a separate class in order to use autoloading? If not can I have a single function like above and complete it's task? 
  Can anyone explain how to call above __autoload function inside my php code? </p>