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

  1. if ( !function_exists( 'spl_autoload_register' ) ) { 
  2. require_once ABSPATH . WPINC . '/compat.php'; 
  3.  
  4. // The function to register. 
  5. $autoload_function = null; 
  6.  
  7. // Optional. Whether the function should throw an exception 
  8. // if the function isn't callable. Default true. 
  9. $throw = true; 
  10.  
  11. // Whether the function should be prepended to the stack. 
  12. // Default false. 
  13. $prepend = false; 
  14.  
  15. // NOTICE! Understand what this does before running. 
  16. $result = spl_autoload_register($autoload_function, $throw, $prepend); 
  17.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/compat.php  
  1. function spl_autoload_register( $autoload_function, $throw = true, $prepend = false ) { 
  2. if ( $throw && ! is_callable( $autoload_function ) ) { 
  3. // String not translated to match PHP core. 
  4. throw new Exception( 'Function not callable' ); 
  5.  
  6. global $_wp_spl_autoloaders; 
  7.  
  8. // Don't allow multiple registration. 
  9. if ( in_array( $autoload_function, $_wp_spl_autoloaders ) ) { 
  10. return; 
  11.  
  12. if ( $prepend ) { 
  13. array_unshift( $_wp_spl_autoloaders, $autoload_function ); 
  14. } else { 
  15. $_wp_spl_autoloaders[] = $autoload_function;