Skip to content

Commit 8c5c03e

Browse files
authored
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
1 parent 94a15cc commit 8c5c03e

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

ext/spl/php_spl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,13 @@ PHP_FUNCTION(spl_autoload_unregister)
582582

583583
if (fcc.function_handler && zend_string_equals_literal(
584584
fcc.function_handler->common.function_name, "spl_autoload_call")) {
585+
php_error_docref(NULL, E_DEPRECATED,
586+
"Using spl_autoload_call() as a callback for spl_autoload_unregister() is deprecated,"
587+
" to remove all registered autoloaders, call spl_autoload_unregister()"
588+
" for all values returned from spl_autoload_functions()");
589+
if (UNEXPECTED(EG(exception))) {
590+
RETURN_THROWS();
591+
}
585592
if (spl_autoload_functions) {
586593
/* Don't destroy the hash table, as we might be iterating over it right now. */
587594
zend_hash_clean(spl_autoload_functions);

ext/spl/tests/bug71204.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ spl_autoload_register(function ($name) {
1313
new A();
1414
?>
1515
--EXPECTF--
16+
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
17+
1618
Fatal error: Uncaught Error: Class "A" not found in %s:%d
1719
Stack trace:
1820
#0 {main}

ext/spl/tests/spl_autoload_002.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ spl_autoload_unregister('spl_autoload');
3535
var_dump(spl_autoload_functions());
3636

3737
?>
38-
--EXPECT--
38+
--EXPECTF--
3939
array(0) {
4040
}
4141
array(1) {
@@ -56,6 +56,8 @@ array(2) {
5656
[1]=>
5757
string(16) "SplAutoloadTest2"
5858
}
59+
60+
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
5961
array(0) {
6062
}
6163
array(1) {

ext/spl/tests/spl_autoload_unregister_without_registrations.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ spl_autoload_unregister("spl_autoload_call") without registrations
55
var_dump(spl_autoload_unregister("spl_autoload_call"));
66
?>
77
Done
8-
--EXPECT--
8+
--EXPECTF--
9+
10+
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
911
bool(true)
1012
Done

0 commit comments

Comments
 (0)