<?php class Autoloader {
public function __construct() {
spl_autoload_register(array($this, 'loader'));
}
private function loader($className) {
$fileName=str_replace("_","/",$className);
//__DIR__ added PHP 5.3
if(defined('__DIR__')){
$currentDir=__DIR__;
}else{
$currentDir=dirname(__FILE__);
}
$fileName=$currentDir.'/'.$fileName.'.php' ;
//echo "Trying to load ".$className.": ".$fileName;
if(is_file($fileName)){
//echo "file exists";
require_once $fileName;
}else{
//echo "file does not exist";
}
}
}
$autoloader = new Autoloader();
?>
|