spl_autoload_register
Registers a function to be autoloaded.
Description
spl_autoload_register( (callable) $autoload_function, (constant) $throw = true, (bool) $prepend = false );
Parameters (3)
- 0. $autoload_function (callable)
- The function to register.
- 1. $throw — Optional. (constant) =>
true
- Whether the function should throw an exception if the function isn't callable. Default true.
- 2. $prepend — Optional. (bool) =>
false
- Whether the function should be prepended to the stack. Default false.
Usage
if ( !function_exists( 'spl_autoload_register' ) ) { require_once ABSPATH . WPINC . '/compat.php'; } // The function to register. $autoload_function = null; // Optional. Whether the function should throw an exception // if the function isn't callable. Default true. $throw = true; // Whether the function should be prepended to the stack. // Default false. $prepend = false; // NOTICE! Understand what this does before running. $result = spl_autoload_register($autoload_function, $throw, $prepend);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/compat.php
- function spl_autoload_register( $autoload_function, $throw = true, $prepend = false ) {
- if ( $throw && ! is_callable( $autoload_function ) ) {
- // String not translated to match PHP core.
- throw new Exception( 'Function not callable' );
- }
- global $_wp_spl_autoloaders;
- // Don't allow multiple registration.
- if ( in_array( $autoload_function, $_wp_spl_autoloaders ) ) {
- return;
- }
- if ( $prepend ) {
- array_unshift( $_wp_spl_autoloaders, $autoload_function );
- } else {
- $_wp_spl_autoloaders[] = $autoload_function;
- }
- }