Returns registered autoload callbacks in their invocation order, or an empty array when none is registered.
What It Does
Composer PSR-4 autoloading supplies a project-level class map Callbacks may be closures, function names, or class-method arrays; do not assume every entry is a string.
Requirements and Compatibility
Available in the PHP runtime; use PHP 8 or later for the shown typed, modern examples.
Syntax, Inputs and Results
The arguments shown below are concrete values for this function; their types and ranges matter. The example checks return data rather than assuming that every operation succeeds.
Example 1: Basic Use
Demonstrates the primary behavior.
<?php
foreach (spl_autoload_functions() as $loader) echo get_debug_type($loader), "\n";
Example 2: Another Case
Handles an alternative input or use case.
<?php
$loader = static function (string $class): void {};
spl_autoload_register($loader);
echo count(spl_autoload_functions()), "\n";
spl_autoload_unregister($loader);
Practical Example
Puts the function into a larger practical task.
<?php
$before = count(spl_autoload_functions());
$callback = static function (string $name): void {};
spl_autoload_register($callback, true, true);
echo count(spl_autoload_functions()) - $before, " added\n";
spl_autoload_unregister($callback);
For production, apply the compatibility and edge-case limits described below.
Important Behavior and Edge Cases
Callbacks may be closures, function names, or class-method arrays; do not assume every entry is a string.
Comparison with Related Functions and Tools
| Subject | Key difference |
|---|---|
| spl_autoload_functions() | Composer PSR-4 autoloading supplies a project-level class map |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Calling spl_autoload_functions() without its required input or supported extension | Check the extension, supply valid arguments, and handle false or exceptions according to the function. |
| Assuming spl_autoload_functions() guarantees a valid or safe image | Inspect the return and avoid exposing debug output to website visitors. |
| Confusing the operation with a related API | Composer PSR-4 autoloading supplies a project-level class map |
Key Takeaways
- Returns registered autoload callbacks in their invocation order, or an empty array when none is registered.
- Callbacks may be closures, function names, or class-method arrays; do not assume every entry is a string.
- Choose the companion API described in the comparison table when the job differs.
Use these examples as a starting point, then validate the result with the actual PHP build, dependencies and inputs used by your application.