334 of 410 menu

The spl_autoload_call Function

The spl_autoload_call function calls all registered autoloaders in an attempt to load the specified class. Unlike spl_autoload_register, which registers autoloaders, this function directly executes them. The only parameter is the name of the class to be loaded.

Syntax

spl_autoload_call(string $class_name): void

Example

Let's try to load a non-existent class without an autoloader:

<?php spl_autoload_call('NonExistentClass'); ?>

Code execution result (error if no autoloaders are registered):

// Nothing will happen if there are no registered autoloaders

Example

Let's create a simple autoloader and try to load a class:

<?php spl_autoload_register(function($class) { echo "Trying to load class: $class\n"; }); spl_autoload_call('TestClass'); ?>

Code execution result:

Trying to load class: TestClass

Example

Let's check the operation with multiple autoloaders:

<?php spl_autoload_register(function($class) { echo "First loader: $class\n"; }); spl_autoload_register(function($class) { echo "Second loader: $class\n"; }); spl_autoload_call('MyClass'); ?>

Code execution result:

First loader: MyClass Second loader: MyClass

See Also

byenru