文字

spl_autoload_call

(PHP 5 >= 5.1.2)

spl_autoload_call尝试调用所有已注册的__autoload()函数来装载请求类

说明

void spl_autoload_call ( string $class_name )

可以直接在程序中手动调用此函数来使用所有已注册的__autoload函数装载类或接口。

参数

class_name

搜索的类名。

返回值

没有返回值。

用户评论:

[#1] Tomek M. [2015-07-19 18:12:09]

Example:

<?php
spl_autoload_register
(function($className) {
    
var_dump($className);
});

//Output: ManuallyCalledClass
spl_autoload_call('ManuallyCalledClass');
?>

[#2] k dot varmark at gmail dot com [2011-02-02 03:40:24]

It should be noted, that calling spl_autoload_call on a child class, and then on its parent class, throws a fatal error.

This happens because autoloading the child class also loads the class it extends. And since spl_autoload_call forcibly calls the registered autoload function(s), not taking into account whether the class exists, a fatal error is thrown:

File: child.class.php

<?php
class Child extends Parent () {
    public function 
__construct () {
        
parent::__construct();
    }
}
?>


File: parent.class.php

<?php
class Parent () {
    public function 
__construct () {

    }
}
?>


File: autoload.php

<?php


    
spl_autoload_call('Child');


    
spl_autoload_call('Parent');

?>

上一篇: 下一篇: