mirror of
https://github.com/php/php-src.git
synced 2025-01-10 13:03:54 +08:00
Fix #48023 (spl_autoload_register didn't store closures)
This commit is contained in:
parent
573961e6f9
commit
cdc6dcfc3c
@ -337,6 +337,7 @@ PHP_FUNCTION(spl_autoload_extensions)
|
||||
typedef struct {
|
||||
zend_function *func_ptr;
|
||||
zval *obj;
|
||||
zval *closure;
|
||||
zend_class_entry *ce;
|
||||
} autoload_func_info;
|
||||
|
||||
@ -345,6 +346,9 @@ static void autoload_func_info_dtor(autoload_func_info *alfi)
|
||||
if (alfi->obj) {
|
||||
zval_ptr_dtor(&alfi->obj);
|
||||
}
|
||||
if (alfi->closure) {
|
||||
zval_ptr_dtor(&alfi->closure);
|
||||
}
|
||||
}
|
||||
|
||||
/* {{{ proto void spl_autoload_call(string class_name) U
|
||||
@ -485,9 +489,14 @@ PHP_FUNCTION(spl_autoload_register)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
alfi.closure = NULL;
|
||||
alfi.ce = fcc.calling_scope;
|
||||
alfi.func_ptr = fcc.function_handler;
|
||||
obj_ptr = fcc.object_ptr;
|
||||
if (Z_TYPE_P(zcallable) == IS_OBJECT) {
|
||||
alfi.closure = zcallable;
|
||||
Z_ADDREF_P(zcallable);
|
||||
}
|
||||
if (error) {
|
||||
efree(error);
|
||||
}
|
||||
@ -531,6 +540,7 @@ PHP_FUNCTION(spl_autoload_register)
|
||||
spl_alfi.func_ptr = spl_func_ptr;
|
||||
spl_alfi.obj = NULL;
|
||||
spl_alfi.ce = NULL;
|
||||
spl_alfi.closure = NULL;
|
||||
zend_hash_add(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload"), &spl_alfi, sizeof(autoload_func_info), NULL);
|
||||
if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) {
|
||||
/* Move the newly created element to the head of the hashtable */
|
||||
|
12
ext/spl/tests/bug48023.phpt
Normal file
12
ext/spl/tests/bug48023.phpt
Normal file
@ -0,0 +1,12 @@
|
||||
--TEST--
|
||||
Bug #48023 (spl_autoload_register didn't addref closures)
|
||||
--FILE--
|
||||
<?php
|
||||
spl_autoload_register(function(){});
|
||||
|
||||
new Foo;
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
Fatal error: Class 'Foo' not found in %s on line %d
|
Loading…
Reference in New Issue
Block a user