333 of 410 menu

The spl_autoload_unregister Function

The spl_autoload_unregister function allows you to remove a previously registered autoload function from the SPL stack. It accepts a callback function as a parameter, which needs to be removed from the list of autoloaders.

Syntax

spl_autoload_unregister(callable $autoload_function);

Example

Let's register and then remove an autoloader:

<?php function my_autoload($class) { include 'classes/' . $class . '.php'; } spl_autoload_register('my_autoload'); spl_autoload_unregister('my_autoload'); ?>

Now the my_autoload function will no longer be called when attempting to autoload an undefined class.

Example

Checking the success of removing an autoloader:

<?php function autoload_one($class) { echo "Trying to load $class\n"; } spl_autoload_register('autoload_one'); $res = spl_autoload_unregister('autoload_one'); var_dump($res); ?>

Code execution result:

true

Example

Attempting to remove a non-existent autoloader:

<?php $res = spl_autoload_unregister('nonexistent_function'); var_dump($res); ?>

Code execution result:

false

See Also

byenru