SPL 函数
php 手册 | 脚本学堂 | 脚本编程 | 网站编程 | 系统管理 | 服务器配置 | 数据库管理 | Php教程 | python教程 | 正则表达式 | 批处理脚本 | Centos教程 | Linux基础教程

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

范例

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 ...


SPL 函数
php 手册 | 脚本学堂 | 脚本编程 | 网站编程 | 系统管理 | 服务器配置 | 数据库管理 | Php教程 | python教程 | 正则表达式 | 批处理脚本 | Centos教程 | Linux基础教程