• <b id="l3qpx"><abbr id="l3qpx"></abbr></b>
  • <th id="l3qpx"><progress id="l3qpx"></progress></th>
      <th id="l3qpx"></th>
      <dd id="l3qpx"><font id="l3qpx"></font></dd>
      <th id="l3qpx"></th>
      0712-2888027 189-8648-0214
      微信公眾號

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

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

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

      時間:2016-10-22來源:風(fēng)信官網(wǎng) 點(diǎn)擊: 708次
      php使用魔術(shù)函數(shù)__autoload自動引入實(shí)例化對象文件,示例代碼如下:
       
      <?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;
       
      //實(shí)例化a對象
      // $a = new \Libs\A;
       
      //實(shí)例化B對象
      // $b = new \Org\B;
       
      //實(shí)例化D對象
      // $d = new \A\B\C\D;
      var_dump($d);
       
       
       ?>
      欄目列表
      推薦內(nèi)容
      熱點(diǎn)內(nèi)容
      展開
      欧美一区二区三区免费A级视频,亚洲精品中文字幕综合,动漫精品中文字幕无码第一页,1024亚洲国产综合 亚太影院 柯西贝尔-游戏赚网
    1. <b id="l3qpx"><abbr id="l3qpx"></abbr></b>
    2. <th id="l3qpx"><progress id="l3qpx"></progress></th>
        <th id="l3qpx"></th>
        <dd id="l3qpx"><font id="l3qpx"></font></dd>
        <th id="l3qpx"></th>