PHP Autoloader

We here at SirGecko hate having to manually require() our class objects, luckily for us PHP has a great, largely underutilized, auto load feature. This autoloader looks inside the specified directories for .class.php files and creates and index to search against. This frees the developer to simply instantiate new objects without needing to worry if they are already loaded or require them explicitly anywhere.

How to use the autoloader

In your project you need only one require statement:

equire_once('sg_autoloader/autoloader.php');
 

Now open autoloader.php and change $sg_dirs to the directories your classes reside in. Remember though, your class filenames must be formatted as ClassName.class.php.

That's it! Go crazy with your project and don't remember to forget those require()s.

Download the autoloader files