tklawsuc Posted July 20, 2007 Share Posted July 20, 2007 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'); Link to comment https://forums.phpfreaks.com/topic/61006-php4-classes-loading/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.