I hope I am posting this in the right place. I have a PHP4 application that has 50+ classes (some custom some 3rd party). One of the things I wanted to implement was something like the __autoload in php5. Can I get some feedback on the performance/efficiency/effectiveness of the following attempt to have an autoload class?
class Loader
{
var $paths = array(); //classes’ paths
function Loader()
{
//specify all our classes and where they can be found either relative to Loader or absolute path
$paths['Class1'] = 'Class1.class.php’;
$paths['Class2'] = '/absolute_path/Class2.class.php’;
// …
}
//load the class file if not yet loaded and return a reference to the requested instance
function &load($class)
{
if (!class_exists($class)) require($paths[$class]);
$inst =& new $class;
return $inst;
}
}
$App =& new Loader();
$inst1 = $App->load('Class1');
inst2 = $App->load('Class2');