A WordPress-centric search engine for devs and theme authors



spl_autoload_register ›

Since4.6.0
Deprecatedn/a
spl_autoload_register ( $autoload_function, $throw = true, $prepend = false )
Parameters: (3)
  • (callable) $autoload_function The function to register.
    Required: Yes
  • (bool) $throw Optional. Whether the function should throw an exception if the function isn't callable. Default true.
    Required: No
    Default: true
  • (bool) $prepend Whether the function should be prepended to the stack. Default false.
    Required: No
    Default: false
Defined at:
Codex:

Registers a function to be autoloaded.



Source

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;
		}
	}