php項目中類的自動加載實(shí)例講解
主要函數(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)文章
PHP調(diào)用Webservice實(shí)例代碼
NuSoap是PHP環(huán)境下的WebService編程工具,用于創(chuàng)建或調(diào)用WebService。2011-07-07幾款免費(fèi)開源的不用數(shù)據(jù)庫的php的cms
下面的幾種內(nèi)容采集系統(tǒng)都是英文版的,全部不需使用數(shù)據(jù)庫,都是國外的免費(fèi)并且開源CMS。對中文支持如何,你自己試試吧!2010-12-12PHP數(shù)據(jù)的提交與過濾基本操作實(shí)例詳解
這篇文章主要介紹了PHP數(shù)據(jù)的提交與過濾基本操作,簡要說明了php數(shù)據(jù)過濾的基本方法并結(jié)合實(shí)例形式分析了php針對各種常見類型數(shù)據(jù)的過濾操作使用技巧,需要的朋友可以參考下2016-11-11php源碼加密 仿微盾PHP加密專家(PHPCodeLock)
php源碼加密 仿照 微盾PHP加密專家(PHPCodeLock),需要的朋友可以參考下。2010-05-05