ext/spl: Deprecate passing spl_autoload_call() to spl_autoload_unregister() (#19422)

RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_passing_spl_autoload_call_to_spl_autoload_unregister
This commit is contained in:
Gina Peter Banyard 2025-08-09 11:23:14 +01:00 committed by GitHub
parent 94a15cc92f
commit 8c5c03e33a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 2 deletions

View file

@ -582,6 +582,13 @@ PHP_FUNCTION(spl_autoload_unregister)
if (fcc.function_handler && zend_string_equals_literal( if (fcc.function_handler && zend_string_equals_literal(
fcc.function_handler->common.function_name, "spl_autoload_call")) { fcc.function_handler->common.function_name, "spl_autoload_call")) {
php_error_docref(NULL, E_DEPRECATED,
"Using spl_autoload_call() as a callback for spl_autoload_unregister() is deprecated,"
" to remove all registered autoloaders, call spl_autoload_unregister()"
" for all values returned from spl_autoload_functions()");
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}
if (spl_autoload_functions) { if (spl_autoload_functions) {
/* Don't destroy the hash table, as we might be iterating over it right now. */ /* Don't destroy the hash table, as we might be iterating over it right now. */
zend_hash_clean(spl_autoload_functions); zend_hash_clean(spl_autoload_functions);

View file

@ -13,6 +13,8 @@ spl_autoload_register(function ($name) {
new A(); new A();
?> ?>
--EXPECTF-- --EXPECTF--
Deprecated: spl_autoload_unregister(): Using spl_autoload_call() as a callback for spl_autoload_unregister() is deprecated, to remove all registered autoloaders, call spl_autoload_unregister() for all values returned from spl_autoload_functions() in %s on line %d
Fatal error: Uncaught Error: Class "A" not found in %s:%d Fatal error: Uncaught Error: Class "A" not found in %s:%d
Stack trace: Stack trace:
#0 {main} #0 {main}

View file

@ -35,7 +35,7 @@ spl_autoload_unregister('spl_autoload');
var_dump(spl_autoload_functions()); var_dump(spl_autoload_functions());
?> ?>
--EXPECT-- --EXPECTF--
array(0) { array(0) {
} }
array(1) { array(1) {
@ -56,6 +56,8 @@ array(2) {
[1]=> [1]=>
string(16) "SplAutoloadTest2" string(16) "SplAutoloadTest2"
} }
Deprecated: spl_autoload_unregister(): Using spl_autoload_call() as a callback for spl_autoload_unregister() is deprecated, to remove all registered autoloaders, call spl_autoload_unregister() for all values returned from spl_autoload_functions() in %s on line %d
array(0) { array(0) {
} }
array(1) { array(1) {

View file

@ -5,6 +5,8 @@ spl_autoload_unregister("spl_autoload_call") without registrations
var_dump(spl_autoload_unregister("spl_autoload_call")); var_dump(spl_autoload_unregister("spl_autoload_call"));
?> ?>
Done Done
--EXPECT-- --EXPECTF--
Deprecated: spl_autoload_unregister(): Using spl_autoload_call() as a callback for spl_autoload_unregister() is deprecated, to remove all registered autoloaders, call spl_autoload_unregister() for all values returned from spl_autoload_functions() in %s on line %d
bool(true) bool(true)
Done Done