主要函數(shù):spl_autoload_register() — 注冊(cè)給定的函數(shù)作為 __autoload() 的實(shí)現(xiàn)
將函數(shù)注冊(cè)到SPL __autoload函數(shù)隊(duì)列中。如果該隊(duì)列中的函數(shù)尚未激活,則激活它們。
如果在你的程序中已經(jīng)實(shí)現(xiàn)了__autoload()函數(shù),它必須顯式注冊(cè)到__autoload()隊(duì)列中。因?yàn)閟pl_autoload_register()函數(shù)會(huì)將Zend Engine中的__autoload()函數(shù)取代為spl_autoload()或spl_autoload_call()。
如果需要多條 autoload 函數(shù),spl_autoload_register() 滿足了此類需求。 它實(shí)際上創(chuàng)建了 autoload 函數(shù)的隊(duì)列,按定義時(shí)的順序逐個(gè)執(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 起可以使用一個(gè)匿名函數(shù)
spl_autoload_register(function ($class) {
include 'classes/' . $class . '.class.php';
});
以上就是全部相關(guān)知識(shí)點(diǎn)內(nèi)容,感謝大家的學(xué)習(xí)和對(duì)腳本之家的支持。
您可能感興趣的文章:- ThinkPHP5 框架引入 Go AOP,PHP AOP編程項(xiàng)目詳解
- thinkphp5框架前后端分離項(xiàng)目實(shí)現(xiàn)分頁(yè)功能的方法分析
- docker-compose部署php項(xiàng)目實(shí)例詳解
- PHP如何實(shí)現(xiàn)阿里云短信sdk靈活應(yīng)用在項(xiàng)目中的方法
- Vue 項(xiàng)目中遇到的跨域問(wèn)題及解決方法(后臺(tái)php)
- 在云虛擬主機(jī)部署thinkphp5項(xiàng)目的步驟詳解
- php+redis在實(shí)際項(xiàng)目中HTTP 500: Internal Server Error故障排除
- PHP項(xiàng)目多語(yǔ)言配置平臺(tái)實(shí)現(xiàn)過(guò)程解析