Wednesday, January 30, 2013

SPL Autoloader

class Autoloader {

  public static function autoload($classname) {

    if(file_exists('../lib/'.$classname . '.class.php')) {
      include_once($classname . '.class.php');
    } else {
      include_once('../lib/model/'.$classname . '.class.php');
    }

    if (!class_exists($classname)) {
      throw new MyException("Class '$classname' not found", 7);
    }

  }

}

spl_autoload_register(array('Autoloader', 'autoload'));

No comments:

Post a Comment