
(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() - 尝试加载未定义的类






