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
-
the spl_autoload_register function,
which registers an autoloader -
the spl_autoload_functions function,
which returns autoloaders -
the spl_autoload_call function,
which calls an autoloader