From e21cb2daeabe459db996407df2113bb47a320937 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 23 Dec 2015 07:48:00 -0800 Subject: [PATCH] Fixed bug #71202 (Autoload function registered by another not activated immediately) --- NEWS | 4 ++++ ext/spl/php_spl.c | 11 +++++++++-- ext/spl/tests/bug71202.phpt | 38 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 ext/spl/tests/bug71202.phpt diff --git a/NEWS b/NEWS index 4dd6361fa0..50a6bbf1e0 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,10 @@ PHP NEWS - Core: . Added support for new HTTP 451 code. (Julien) +- SPL: + . Fixed bug #71202 (Autoload function registered by another not activated + immediately). (Laruence) + - Standard: . Fixed bug #71190 (substr_replace converts integers in original $search array to strings). (Laruence) diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index e89caa2059..b2f59328d2 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -417,11 +417,17 @@ PHP_FUNCTION(spl_autoload_call) } if (SPL_G(autoload_functions)) { + HashPosition pos; + zend_ulong num_idx; int l_autoload_running = SPL_G(autoload_running); SPL_G(autoload_running) = 1; lc_name = zend_string_alloc(Z_STRLEN_P(class_name), 0); zend_str_tolower_copy(ZSTR_VAL(lc_name), Z_STRVAL_P(class_name), Z_STRLEN_P(class_name)); - ZEND_HASH_FOREACH_STR_KEY_PTR(SPL_G(autoload_functions), func_name, alfi) { + zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &pos); + while (zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &num_idx, &pos) == HASH_KEY_IS_STRING) { + if ((alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &pos)) == NULL) { + continue; + } zend_call_method(Z_ISUNDEF(alfi->obj)? NULL : &alfi->obj, alfi->ce, &alfi->func_ptr, ZSTR_VAL(func_name), ZSTR_LEN(func_name), retval, 1, class_name, NULL); zend_exception_save(); if (retval) { @@ -431,7 +437,8 @@ PHP_FUNCTION(spl_autoload_call) if (zend_hash_exists(EG(class_table), lc_name)) { break; } - } ZEND_HASH_FOREACH_END(); + zend_hash_move_forward_ex(SPL_G(autoload_functions), &pos); + } zend_exception_restore(); zend_string_free(lc_name); SPL_G(autoload_running) = l_autoload_running; diff --git a/ext/spl/tests/bug71202.phpt b/ext/spl/tests/bug71202.phpt new file mode 100644 index 0000000000..d26d7e1f35 --- /dev/null +++ b/ext/spl/tests/bug71202.phpt @@ -0,0 +1,38 @@ +--TEST-- +Bug #71202 (Autoload function registered by another not activated immediately) +--FILE-- + +--EXPECT-- +okey, done -- 2.40.0