在課程計畫審查網站中有底下的程式碼
function __autoload($class_name){
global $rootpath;
$file = $rootpath.'include/table/'.$class_name.'.class.php';
if(!file_exists($file)){
$file = $rootpath.'include/class/'.$class_name.'.class.php';
if(!file_exists($file)){
$file = $rootpath.'include/systab/'.$class_name.'.class.php';
if(!file_exists($file)){
$file = $rootpath.'include/class/'.$class_name.'/'.$class_name.'.class.php';
if(!file_exists($file)){
$str=file_get_contents($rootpath.'include/template.php');
$str=str_replace('CLASSNAME',$class_name,$str);
fileWrite($rootpath.'cache/','tmpclass.php',$str);
$file=$rootpath.'cache/'.'tmpclass.php';
}
}
}
}
include_once ($file);
}
在 php5.3以後建議用
spl_autoload_register(function ($class_name) {
global $rootpath;
$file = $rootpath.'include/table/'.$class_name.'.class.php';
if(!file_exists($file)){
$file = $rootpath.'include/class/'.$class_name.'.class.php';
if(!file_exists($file)){
$file = $rootpath.'include/systab/'.$class_name.'.class.php';
if(!file_exists($file)){
$file = $rootpath.'include/class/'.$class_name.'/'.$class_name.'.class.php';
if(!file_exists($file)){
$str=file_get_contents($rootpath.'include/template.php');
$str=str_replace('CLASSNAME',$class_name,$str);
fileWrite($rootpath.'cache/','tmpclass.php',$str);
$file=$rootpath.'cache/'.'tmpclass.php';
}
}
}
}
include_once ($file);
});
沒有留言:
張貼留言