title: spl_autoload_register not working
body: <p>I have created 5 folders containing 5 classes (Ad_Class, Blocked_Class, Friend_Class, Image_Class, Profile_Class) in the main directory. I also created the respective classes within the mentioned folders with the exact name as the folders. i.e. if folder name is Ad_Class then the class within the folder is also the same as the folder name as in "class Ad_Class. </p>
  
  <p>In the index.php file I wrote the following code:</p>
  
  <pre><code>function Ad_Class($name)
  {
      include "Ad_Class/$name.php";
  }
  function Blocked_Class($name)
  {
      include "Blocked_Class/$name.php";
  }
  function Friend_Class($name)
  {
      include "Friend_Class/$name.php";
  }
  function Image_Class($name)
  {
      include "Image_Class/$name.php";
  }
  function Profile_Class($name)
  {
      include "Profile_Class/$name.php";
  }
  
  spl_autoload_register("Ad_Class");
  spl_autoload_register("Blocked_Class");
  spl_autoload_register("Friend_Class");
  spl_autoload_register("Image_Class");
  spl_autoload_register("Profile_Class");
  
  $a = new Ad_Class;
  $b = new Blocked_Class;
  $c = new Blocked_Class;
  $d = new Image_Class;
  $e = new Profile_Class;
  </code></pre>
  
  <p>After executing the above code I get the below warnings:</p>
  
  <pre><code>Warning: include(Ad_Class/Blocked_Class.php): failed to open stream: No such file or directory in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 4
  
  Warning: include(): Failed opening 'Ad_Class/Blocked_Class.php' for inclusion (include_path='.;C:\Users\Robert\Documents\web development\xampp\php\PEAR') in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 4
  
  Warning: include(Ad_Class/Image_Class.php): failed to open stream: No such file or directory in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 4
  
  Warning: include(): Failed opening 'Ad_Class/Image_Class.php' for inclusion (include_path='.;C:\Users\Robert\Documents\web development\xampp\php\PEAR') in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 4
  
  Warning: include(Blocked_Class/Image_Class.php): failed to open stream: No such file or directory in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 8
  
  Warning: include(): Failed opening 'Blocked_Class/Image_Class.php' for inclusion (include_path='.;C:\Users\Robert\Documents\web development\xampp\php\PEAR') in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 8
  
  Warning: include(Friend_Class/Image_Class.php): failed to open stream: No such file or directory in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 12
  
  Warning: include(): Failed opening 'Friend_Class/Image_Class.php' for inclusion (include_path='.;C:\Users\Robert\Documents\web development\xampp\php\PEAR') in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 12
  
  Warning: include(Ad_Class/Profile_Class.php): failed to open stream: No such file or directory in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 4
  
  Warning: include(): Failed opening 'Ad_Class/Profile_Class.php' for inclusion (include_path='.;C:\Users\Robert\Documents\web development\xampp\php\PEAR') in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 4
  
  Warning: include(Blocked_Class/Profile_Class.php): failed to open stream: No such file or directory in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 8
  
  Warning: include(): Failed opening 'Blocked_Class/Profile_Class.php' for inclusion (include_path='.;C:\Users\Robert\Documents\web development\xampp\php\PEAR') in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 8
  
  Warning: include(Friend_Class/Profile_Class.php): failed to open stream: No such file or directory in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 12
  
  Warning: include(): Failed opening 'Friend_Class/Profile_Class.php' for inclusion (include_path='.;C:\Users\Robert\Documents\web development\xampp\php\PEAR') in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 12
  
  Warning: include(Image_Class/Profile_Class.php): failed to open stream: No such file or directory in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 16
  
  Warning: include(): Failed opening 'Image_Class/Profile_Class.php' for inclusion (include_path='.;C:\Users\Robert\Documents\web development\xampp\php\PEAR') in C:\Users\Robert\Documents\web development\xampp\htdocs\xampp\web_development\development.php on line 16
  </code></pre>
  
  <p>Why is this happening? Can anyone explain?</p>
  
  <p>Update: I found the following code to work. If you have any suggestions please feel free to share!</p>
  
  <pre><code>function ad_class($class)
  {
      if(!class_exists($class) &amp;&amp; $class == "Ad_Class")
      {
          include "Ad_Class/$class" . ".php";
      }
      elseif(!class_exists($class))
      {
          return;
      }
  }
  
  function blocked_class($class)
  {
      if(!class_exists($class) &amp;&amp; $class == "Blocked_Class")
      {
          include "Blocked_Class/$class" . ".php";
      }
      elseif(!class_exists($class))
      {
          return;
      }
  }
  
  function friend_class($class)
  {
      if(!class_exists($class) &amp;&amp; $class == "Friend_Class")
          {
          include "Friend_Class/$class" . ".php";
      }
      elseif(!class_exists($class))
      {
          return;
      }
  }
  
  function image_class($class)
  {
      if(!class_exists($class) &amp;&amp; $class == "Image_Class")
      {
          include "Image_Class/$class" . ".php";
      }
      elseif(!class_exists($class))
      {
          return;
      }
  }
  
  function profile_class($class)
  {
          if(!class_exists($class) &amp;&amp; $class == "Profile_Class")
      {
          include "Profile_Class/$class" . ".php";
      }
      elseif(!class_exists($class))
      {
          return;
      }
  }
  spl_autoload_register("ad_class");
  spl_autoload_register("blocked_class");
  spl_autoload_register("friend_class");
  spl_autoload_register("image_class");
  spl_autoload_register("profile_class");
  
  $a = new Ad_Class;
  $a-&gt;ad();
  
  $b = new Blocked_Class;
  $b-&gt;block();
  
  $c = new Friend_Class;
  $c-&gt;fr();
  
  $d = new Image_Class;
  $d-&gt;image();
  </code></pre>
  
  <p>It produces the following:
  Advertising
  Blocked
  Friend
  Image</p>
  
  <p>which is nothing more than displaying the class name of the instantiated object to see if the code worked correclty in loading classes.</p>