久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php如何實(shí)現(xiàn)類的自動(dòng)加載

      php實(shí)現(xiàn)類自動(dòng)加載的方法:1、使用“__autoload”魔術(shù)函數(shù)實(shí)現(xiàn)加載類;2、通過“spl_autoload_register”函數(shù)代替autoload函數(shù)作用。

      php如何實(shí)現(xiàn)類的自動(dòng)加載

      推薦:《PHP視頻教程》

      類的自動(dòng)加載是指,在外面的頁面中,并不需要去“引入”類文件,但是程序會(huì)在需要的時(shí)候動(dòng)態(tài)加載需要的類文件。

      方法1:使用__autoload魔術(shù)函數(shù)

      當(dāng)程序需要某個(gè)類時(shí),就會(huì)去調(diào)用該函數(shù),該函數(shù)我們需要自己去定義并在其中寫好加載類文件的通用語句。

      <?php     //需要類是自動(dòng)調(diào)用,而且會(huì)傳進(jìn)來一個(gè)類名,這個(gè)案例的文件名為21A.class.php,類名為A      function __autoload($className){       require "./21".$className.".class.php";     }     $o1 = new A();     $o1->v1 = 10;     echo "<br/>v1:".$o1->v1;   ?>

      方法2:使用spl_autoload_register函數(shù)

      該函數(shù)的作用是生命多個(gè)可以用來代替autoload函數(shù)作用的函數(shù),語法如下:spl_autoload_regist("函數(shù)名1");如果用spl_autoload_register,autoload就失效了。

      <?php     //注冊(cè)兩個(gè)用于自動(dòng)加載的函數(shù)名     spl_autoload_register('auto1');     spl_autoload_register('auto2');     function auto1($className){       $file = "./21".$className.".class.php";       if(file_exists($file)){         require "./21".$className.".class.php";       }     }     function auto1($className){       $file = "./22".$className.".class.php";       if(file_exists($file)){         require "./22".$className.".class.php";       }     }     //如果需要一個(gè)雷,但這個(gè)頁面還沒有記載,就會(huì)依次調(diào)用auto1和auto2,知道找到該類文件并加載   ?>

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)