国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php 類自動載入的方法

2024-05-04 23:35:52
字體:
來源:轉載
供稿:網友

在PHP5之前,各個PHP框架如果要實現類的自動加載,一般都是按照某種約定自己實現一個遍歷目錄,自動加載所有符合約定規則的文件的類或函數。 當然,PHP5之前對面向對象的支持并不是太好,類的使用也沒有現在頻繁。 我們來詳細探討下吧。

php 類自動載入方法

 

 
  1. <?php 
  2. class inload  
  3. /** 
  4. * 類自動載入,不需要由開發者調用 
  5. * 
  6. * @param string $class 類文件 
  7. */ 
  8. private function autoload( $class ) 
  9. ifemptyempty($class) ) 
  10. throw new QException('加載文件不存在'.$class); 
  11. else 
  12. {  
  13. require _SPRING_.'/_Core/SpringMap.php'//框架地圖 
  14. if(! file_exists$source[$class]['file'] ) ) 
  15. throw new QException('加載文件不存在'.$class); 
  16. }  
  17. require $source[$class]['file']; 
  18.  
  19. /** 
  20. * 注冊或取消注冊一個自動類載入方法 
  21. * 
  22. * 該方法參考 Zend Framework 
  23. * 
  24. * @param string $class 提供自動載入服務的類 
  25. * @param boolean $enabled 啟用或禁用該服務 
  26. */ 
  27. private function registerAutoload($class = 'Interpreter' , $enabled = true) 
  28. if (!function_exists('spl_autoload_register')) 
  29. throw new QException('spl_autoload 不存在這個PHP的安裝'); 
  30. if ($enabled === true) 
  31. spl_autoload_register(array($class'autoload')); 
  32. else 
  33. spl_autoload_unregister(array($class'autoload')); 
  34.  
  35. /** 
  36. * 析構函數 
  37. */ 
  38. public function __destruct() 
  39. self::registerAutoload('Interpreter' , false); 
  40. }  

以上所述就是本文的全部內容了,希望大家能夠喜歡。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 会东县| 屯门区| 钟山县| 池州市| 珠海市| 垦利县| 安乡县| 法库县| 沛县| 许昌市| 阿勒泰市| 呼伦贝尔市| 昆明市| 远安县| 蓬安县| 建宁县| 孟州市| 昌黎县| 襄城县| 高雄县| 丹巴县| 博野县| 宜春市| 洛浦县| 赤城县| 论坛| 湘乡市| 井研县| 屯昌县| 个旧市| 安平县| 乌恰县| 年辖:市辖区| 海丰县| 泰宁县| 申扎县| 敦煌市| 苏州市| 珲春市| 龙海市| 秭归县|