《PHP編程:php類自動(dòng)加載器實(shí)現(xiàn)方法》要點(diǎn):
本文介紹了PHP編程:php類自動(dòng)加載器實(shí)現(xiàn)方法,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
PHP教程本文實(shí)例講述了php類自動(dòng)加載器實(shí)現(xiàn)辦法.分享給大家供大家參考.具體如下:
PHP教程這里autoload 可兼容以下格式:
PHP教程Cache_File_Json
class_xxx.php
xxx.class.php
? xxx.php
PHP教程php代碼如下:
PHP教程
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;
}
PHP教程希望本文所述對(duì)大家的php程序設(shè)計(jì)有所贊助.
維易PHP培訓(xùn)學(xué)院每天發(fā)布《PHP編程:php類自動(dòng)加載器實(shí)現(xiàn)方法》等實(shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請(qǐng)注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/9401.html