PHP 7.0.6 Released

spl_autoload_call

(PHP 5 >= 5.1.2, PHP 7)

spl_autoload_callTry all registered __autoload() function to load the requested class

Description

void spl_autoload_call ( string $class_name )

This function can be used to manually search for a class or interface using the registered __autoload functions.

Parameters

class_name

The class name being searched.

Return Values

No value is returned.

User Contributed Notes

k dot varmark at gmail dot com
5 years ago
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

/*    works fine    */
   
spl_autoload_call('Child');

/*    throws: Fatal error: Cannot redeclare class Parent in /parent.class.php on line 2    */
   
spl_autoload_call('Parent');

?>
Tomek M.
9 months ago
Example:

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

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