Heim  >  Artikel  >  php教程  >  php类自动加载器

php类自动加载器

PHP中文网
PHP中文网Original
2016-05-25 17:13:261042Durchsuche

跳至

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;
}

                   

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn