Return to Snippet

Revision: 7057
at July 2, 2008 13:05 by luizlopes


Initial Code
<?php
    function __autoload($class_name)
    {
        //class directories
        $directorys = array(
            'classes/',
            'classes/otherclasses/',
            'classes2/',
            'module1/classes/'
        );
       
        //for each directory
        foreach($directorys as $directory)
        {
            //see if the file exsists
            if(file_exists($directory.$class_name . '.php'))
            {
                require_once($directory.$class_name . '.php');
                //only require the class once, so quit after to save effort (if you got more, then name them something else
                return;
            }           
        }
    }
?>

Initial URL
http://us3.php.net/__autoload

Initial Description
http://us.php.net/manual/en/language.oop5.autoload.php#82614

Initial Title
Autoloading Objects

Initial Tags
class, php

Initial Language
PHP