• <dl id="2u8ki"><small id="2u8ki"></small></dl>
    • <rt id="2u8ki"><em id="2u8ki"></em></rt>
    • <menu id="2u8ki"></menu>
      0712-2888027 189-8648-0214
      微信公眾號

      孝感風(fēng)信網(wǎng)絡(luò)科技有限公司微信公眾號

      當(dāng)前位置:主頁 > 技術(shù)支持 > PHP > php使用魔術(shù)函數(shù)__autoload自動引入實例化對象文件

      php使用魔術(shù)函數(shù)__autoload自動引入實例化對象文件

      時間:2016-10-22來源:風(fēng)信官網(wǎng) 點擊: 708次
      php使用魔術(shù)函數(shù)__autoload自動引入實例化對象文件,示例代碼如下:
       
      <?php 
       
      //魔術(shù)函數(shù) __autoload
      function __autoload($className)  //  Libs\A      =>   ./Libs/A.php
      {
      //將反斜線 \  替換成 /
      $class = str_replace('\\','/',$className);  //  Libs/A  =>  ./Libs/A.php
      //拼接文件的路徑
      $path = './'.$class.'.php';
      //檢測文件是否存在
      if(file_exists($path)) {
      //引入該類文件
      include $path;
      }
      }
       
      //如果當(dāng)前類的空間路徑跟文件所處的路徑保持一致的話 很容易獲取到當(dāng)前類文件的位置
      // $obj = new \Org\Obj;
       
      //實例化a對象
      // $a = new \Libs\A;
       
      //實例化B對象
      // $b = new \Org\B;
       
      //實例化D對象
      // $d = new \A\B\C\D;
      var_dump($d);
       
       
       ?>
      欄目列表
      推薦內(nèi)容
      熱點內(nèi)容
      展開
      中文字幕无码AV黄片,亚洲天堂日本美女,国产亚洲色婷婷久久99精品91,午夜无码不卡视频 99久色图精品国产 精品熟女少妇A∨免费久久
    • <dl id="2u8ki"><small id="2u8ki"></small></dl>
      • <rt id="2u8ki"><em id="2u8ki"></em></rt>
      • <menu id="2u8ki"></menu>