__autoload catch exceptions ........

liunx

Guest
Hi.
I never used _autoload in my script and these are the first
steps with this feature.
I've managed this snippet:

class AutoLoad_Exception extends Exception {}
function __autoload($className){
$root= dirname(__FILE__).DIRECTORY_SEPARATOR;
$fileName = $root.str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if(!file_exists($fileName)){
return eval("class {$className}{public function __construct(){throw new AutoLoad_Exception('File '.__CLASS__.' not found!');}}");
}
require_once $fileName;
if(stripos($className, 'Interface')===false){
if(!class_exists($className,false)){
return eval("class {$className}{public function __construct(){throw new AutoLoad_Exception('Class '.__CLASS__.' not found!');}}");
}
}
else{
if(!interface_exists($className,false)){
return eval("class {$className}{public function __construct(){throw new AutoLoad_Exception('Interface '.__CLASS__.' not found!');}}");
}
}

}
try{
$userModel=new models_UserModel();
}
catch (AutoLoad_Exception $e){
echo $e->getMessage();
exit();
}


What do you think about it ?

A thing that I don't like at all is the class name :(

Bye.
 
Top