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

php項目中類的自動加載實(shí)例講解

 更新時間:2019年09月12日 15:20:43   作者:熱血奪刀  
在本篇文章里小編給大家整理的是關(guān)于php項目中類的自動加載的實(shí)例內(nèi)容以及相關(guān)代碼,需要的朋友們學(xué)習(xí)下。

主要函數(shù):spl_autoload_register() — 注冊給定的函數(shù)作為 __autoload() 的實(shí)現(xiàn)

將函數(shù)注冊到SPL __autoload函數(shù)隊列中。如果該隊列中的函數(shù)尚未激活,則激活它們。

如果在你的程序中已經(jīng)實(shí)現(xiàn)了__autoload()函數(shù),它必須顯式注冊到__autoload()隊列中。因?yàn)閟pl_autoload_register()函數(shù)會將Zend Engine中的__autoload()函數(shù)取代為spl_autoload()或spl_autoload_call()。

如果需要多條 autoload 函數(shù),spl_autoload_register() 滿足了此類需求。 它實(shí)際上創(chuàng)建了 autoload 函數(shù)的隊列,按定義時的順序逐個執(zhí)行。相比之下, __autoload() 只可以定義一次。

<?php

// $class 類名
function autoloader_1($class) {
  include 'classes/' . $class . '.class.php';
}

function autoloader_2($class) {
  include 'classes/' . $class . '.class.php';
}

// 可以多次使用,但 __autoload() 函數(shù)只能使用一次。
spl_autoload_register('autoloader_1');
spl_autoload_register('autoloader_2');

// 或者,自 PHP 5.3.0 起可以使用一個匿名函數(shù)
spl_autoload_register(function ($class) {
  include 'classes/' . $class . '.class.php';
});

以上就是全部相關(guān)知識點(diǎn)內(nèi)容,感謝大家的學(xué)習(xí)和對腳本之家的支持。

相關(guān)文章

最新評論