Jump to content

PHP4 classes loading


tklawsuc

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.