導航首頁 ? 技術教程 ? PHP:spl_autoload_register()的用法_spl函數
    全站頭部文字 我要出現在這里
    PHP:spl_autoload_register()的用法_spl函數 518 2023-12-15   

    spl_autoload_register

    (PHP 5 >= 5.1.2)

    spl_autoload_register — 注冊__autoload()函數

    說明

    bool spl_autoload_register ([ callback $autoload_function ] )

    將函數注冊到SPL __autoload函數棧中。如果該棧中的函數尚未激活,則激活它們。

    如果在你的程序中已經實現了__autoload函數,它必須顯式注冊到__autoload棧中。因為 spl_autoload_register()函數會將Zend Engine中的__autoload函數取代為spl_autoload()或spl_autoload_call()。

    參數

    autoload_function

    欲注冊的自動裝載函數。如果沒有提供任何參數,則自動注冊autoload的默認實現函數spl_autoload()。

    返回值

    成功時返回 TRUE, 或者在失敗時返回 FALSE

    更新日志

    版本 說明 5.3.0 Namespaces support was introduced. 5.3.0 The prepend parameter was added.

    范例

    Example #1 spl_autoload_register() example

    <?php

    namespace Foobar;

    class Foo {
        static public function test($name) {
            print '[['. $name .']]';
        }
    }

    spl_autoload_register(__NAMESPACE__ .'::Foo::test'); // As of PHP 5.3.0

    new InexistentClass;

    ?>

    以上例程的輸出類似于:

    [[Foobar::InexistentClass]]
    Fatal error: Class 'Foobar::InexistentClass' not found in ...
    

    參見

    __autoload() - 嘗試加載未定義的類


    !!!站長長期在線接!!!

    網站、小程序:定制開發/二次開發/仿制開發等

    各種疑難雜癥解決/定制接口/定制采集等

    站長微信:lxwl520520

    站長QQ:1737366103