diff options
Diffstat (limited to 'ext/spl/php_spl.c')
-rw-r--r-- | ext/spl/php_spl.c | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 7cb6661033..87fb2ae37b 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | + | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -307,7 +307,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha Default implementation for __autoload() */ PHP_FUNCTION(spl_autoload) { - int found = 0, pos_len, pos1_len; + int pos_len, pos1_len; char *pos, *pos1; zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); @@ -333,32 +333,12 @@ PHP_FUNCTION(spl_autoload) pos1_len = pos_len; } if (spl_autoload(class_name, lc_name, pos, pos1_len)) { - found = 1; break; /* loaded */ } pos = pos1 ? pos1 + 1 : NULL; pos_len = pos1? pos_len - pos1_len - 1 : 0; } zend_string_free(lc_name); - - if (!found && !SPL_G(autoload_running)) { - /* For internal errors, we generate E_ERROR, for direct calls an exception is thrown. - * The "scope" is determined by an opcode, if it is ZEND_FETCH_CLASS we know function was called indirectly by - * the Zend engine. - */ - zend_execute_data *ex = EX(prev_execute_data); - - while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { - ex = ex->prev_execute_data; - } - if (ex && - ex->opline->opcode != ZEND_FETCH_CLASS && - ex->opline->opcode != ZEND_NEW) { - zend_throw_exception_ex(spl_ce_LogicException, 0, "Class %s could not be loaded", ZSTR_VAL(class_name)); - } else { - zend_throw_error(zend_ce_error, "Class %s could not be loaded", ZSTR_VAL(class_name)); - } - } } /* }}} */ /* {{{ proto string spl_autoload_extensions([string file_extensions]) @@ -417,11 +397,15 @@ 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) { + alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &pos); 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 +415,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; @@ -654,10 +639,14 @@ PHP_FUNCTION(spl_autoload_unregister) if (SPL_G(autoload_functions)) { if (ZSTR_LEN(lc_name) == sizeof("spl_autoload_call") - 1 && !strcmp(ZSTR_VAL(lc_name), "spl_autoload_call")) { /* remove all */ - zend_hash_destroy(SPL_G(autoload_functions)); - FREE_HASHTABLE(SPL_G(autoload_functions)); - SPL_G(autoload_functions) = NULL; - EG(autoload_func) = NULL; + if (!SPL_G(autoload_running)) { + zend_hash_destroy(SPL_G(autoload_functions)); + FREE_HASHTABLE(SPL_G(autoload_functions)); + SPL_G(autoload_functions) = NULL; + EG(autoload_func) = NULL; + } else { + zend_hash_clean(SPL_G(autoload_functions)); + } success = SUCCESS; } else { /* remove specific */ @@ -768,7 +757,7 @@ PHPAPI zend_string *php_spl_object_hash(zval *obj) /* {{{*/ } hash_handle = SPL_G(hash_mask_handle)^(intptr_t)Z_OBJ_HANDLE_P(obj); - hash_handlers = SPL_G(hash_mask_handlers)^(intptr_t)Z_OBJ_HT_P(obj); + hash_handlers = SPL_G(hash_mask_handlers); return strpprintf(32, "%016lx%016lx", hash_handle, hash_handlers); } |