PHP5 Autoload classes

This is really handy for medium to large size projects. You don’t have to remember to put a set of require_once functions in every file.  I usually put this in a config file that’s loaded early and on every page.

<?php
function __autoload($class_name) {
   require_once $class_name . ‘.php';
}

$obj  = new MyClass1();
$obj2 = new MyClass2();
?>

See http://us2.php.net/manual/en/language.oop5.autoload.php for more information.

Comments are closed.