Home > php教程 > PHP源码 > body text

php类自动加载器

PHP中文网
Release: 2016-05-25 17:13:26
Original
1031 people have browsed it

跳至

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;
}
Copy after login

                   

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!