spl_autoload()
spl_autoload() — Default implementation for __autoload().
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.1.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This function is intended to be used as a default implementation for __autoload(). If nothing else is specified and spl_autoload_register() is called without any parameters then spl_autoload() will be used for any later call to __autoload().
Signature
spl_autoload(string $class, ?string $file_extensions = null): void
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $class | string | The name of the class being instantiated. When calling the function, the name of the class with the namespace is passed to the parameter. The class will not contain the leading backslash of a fully-qualified identifier. |
| $file_extensions | ?string | By default it checks all include_paths to contain filenames built up by the lowercase class name appended by the filename extensions .inc and .php. |
Return value
No value is returned.
Example
The PHP manual ships no example for spl_autoload(); the signature and the parameter table above are the contract.
Changelog
| Version | Change |
|---|---|
| 8.0.0 | file_extensions is now nullable. |
All PHP 8.5 built-in functions
Reference card built from the PHP manual page spl_autoload() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.