欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php類自動加載器實現(xiàn)方法

 更新時間:2015年07月28日 11:51:17   作者:yak  
這篇文章主要介紹了php類自動加載器實現(xiàn)方法,涉及php針對文件的讀取、判斷及字符串操作的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了php類自動加載器實現(xiàn)方法。分享給大家供大家參考。具體如下:

這里autoload 可兼容以下格式:

Cache_File_Json
class_xxx.php
xxx.class.php
  xxx.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程序設計有所幫助。

相關文章

最新評論