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

phpspl_autoload_call(string $class_name): void

Example

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

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

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

php// Nothing will happen if there are no registered autoloaders

Example

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

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

spl_autoload_call('TestClass');
?>

Code execution result:

phpTrying to load class: TestClass

Example

Let's check the operation with multiple autoloaders:

php<?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:

phpFirst loader: MyClass
Second loader: MyClass

See Also