主要函數(shù):spl_autoload_register() — 注冊給定的函數(shù)作為 __autoload() 的實現(xiàn)
將函數(shù)注冊到SPL __autoload函數(shù)隊列中。如果該隊列中的函數(shù)尚未激活,則激活它們。
如果在你的程序中已經(jīng)實現(xiàn)了__autoload()函數(shù),它必須顯式注冊到__autoload()隊列中。因為spl_autoload_register()函數(shù)會將Zend Engine中的__autoload()函數(shù)取代為spl_autoload()或spl_autoload_call()。
如果需要多條 autoload 函數(shù),spl_autoload_register() 滿足了此類需求。 它實際上創(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)知識點內(nèi)容,感謝大家的學(xué)習(xí)和對腳本之家的支持。
您可能感興趣的文章:- ThinkPHP5 框架引入 Go AOP,PHP AOP編程項目詳解
- thinkphp5框架前后端分離項目實現(xiàn)分頁功能的方法分析
- docker-compose部署php項目實例詳解
- PHP如何實現(xiàn)阿里云短信sdk靈活應(yīng)用在項目中的方法
- Vue 項目中遇到的跨域問題及解決方法(后臺php)
- 在云虛擬主機部署thinkphp5項目的步驟詳解
- php+redis在實際項目中HTTP 500: Internal Server Error故障排除
- PHP項目多語言配置平臺實現(xiàn)過程解析