spl_autoload_register( callable $autoload_function, bool $throw = true, bool $prepend = false )

Registers a function to be autoloaded.


Description Description


Parameters Parameters

$autoload_function

(callable) (Required) The function to register.

$throw

(bool) (Optional) Whether the function should throw an exception if the function isn't callable.

Default value: true

$prepend

(bool) (Optional) Whether the function should be prepended to the stack.

Default value: false


Top ↑

Source Source

File: wp-includes/spl-autoload-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;
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.6.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.