(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() - 嘗試加載未定義的類