首頁  >  文章  >  php教程  >  php类自动加载器

php类自动加载器

PHP中文网
PHP中文网原創
2016-05-25 17:13:261042瀏覽

跳至

function __autoload($className){
	
	$dirs=explode('_',$className);
	$fileName=array_pop($dirs);
	//print_r($dirs);
	$filePath=$fileName;
	if(is_array($dirs)  &&  (count($dirs) > 0)){
		//echo '\n---\n'; print_r($dirs);
		$dirPath='';
		foreach ($dirs as $dir){
			if($dir){
				$dirPath.=strtolower($dir).DIRECTORY_SEPARATOR;
			}
			
		}
		$filePath=$dirPath.$fileName.'.php';
		
	}else {
		
		
		if( file_exists('class_'.$fileName.'.php')){
			$filePath='class_'.$fileName.'.php';
		}else {
			if( file_exists($fileName.'.class.php')){
				$filePath=$fileName.'.class.php';
			} else {
				$filePath=$fileName.'.php';
			}
		}	 
		
	}
	//var_dump($filePath);
	require $filePath;
}

                   

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn