diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-04-27 12:33:29 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-04-27 12:33:29 +0200 |
commit | fd00c7cf10f68e9ebe31a6b8ec563e5aeb80a535 (patch) | |
tree | bd5ce8818df4328bed5ea4b45afa2ed8f72f330e | |
parent | 74f1547591cfb8244dae3b4afdb6c26164a80772 (diff) | |
download | php-git-fd00c7cf10f68e9ebe31a6b8ec563e5aeb80a535.tar.gz |
Pass existing lcname to check_magic_method_implementation
-rw-r--r-- | Zend/zend_API.c | 11 | ||||
-rw-r--r-- | Zend/zend_API.h | 3 | ||||
-rw-r--r-- | Zend/zend_compile.c | 10 |
3 files changed, 11 insertions, 13 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 636cf703cc..4aa76ca111 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1958,17 +1958,13 @@ ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *mod } /* }}} */ -ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type) /* {{{ */ +ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, zend_string *lcname, int error_type) /* {{{ */ { - zend_string *lcname; - if (ZSTR_VAL(fptr->common.function_name)[0] != '_' || ZSTR_VAL(fptr->common.function_name)[1] != '_') { return; } - lcname = zend_string_tolower(fptr->common.function_name); - if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME) && fptr->common.num_args != 0) { zend_error(error_type, "Destructor %s::%s() cannot take arguments", ZSTR_VAL(ce->name), ZEND_DESTRUCTOR_FUNC_NAME); } else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME) && fptr->common.num_args != 0) { @@ -2018,8 +2014,6 @@ ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, } else if (zend_string_equals_literal(lcname, "__unserialize") && fptr->common.num_args != 1) { zend_error(error_type, "Method %s::__unserialize() must take exactly 1 argument", ZSTR_VAL(ce->name)); } - - zend_string_release_ex(lcname, 0); } /* }}} */ @@ -2237,7 +2231,8 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio reg_function = NULL; } if (reg_function) { - zend_check_magic_method_implementation(scope, reg_function, error_type); + zend_check_magic_method_implementation( + scope, reg_function, lowercase_name, error_type); } } ptr++; diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 44c24bbca1..51353ad710 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -319,7 +319,8 @@ ZEND_API int zend_startup_module_ex(zend_module_entry *module); ZEND_API int zend_startup_modules(void); ZEND_API void zend_collect_module_handlers(void); ZEND_API void zend_destroy_modules(void); -ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type); +ZEND_API void zend_check_magic_method_implementation( + const zend_class_entry *ce, const zend_function *fptr, zend_string *lcname, int error_type); ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry); ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce); diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 381a180f29..a83d4d3d18 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6070,7 +6070,7 @@ static void add_stringable_interface(zend_class_entry *ce) { zend_string_init("stringable", sizeof("stringable") - 1, 0); } -void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_bool has_body) /* {{{ */ +zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_bool has_body) /* {{{ */ { zend_class_entry *ce = CG(active_class_entry); zend_bool in_interface = (ce->ce_flags & ZEND_ACC_INTERFACE) != 0; @@ -6163,7 +6163,7 @@ void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_boo zend_check_magic_method_attr(fn_flags, ce, "__unserialize", 0); } - zend_string_release_ex(lcname, 0); + return lcname; } /* }}} */ @@ -6236,6 +6236,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /* zend_ast *stmt_ast = decl->child[2]; zend_ast *return_type_ast = decl->child[3]; zend_bool is_method = decl->kind == ZEND_AST_METHOD; + zend_string *method_lcname; zend_class_entry *orig_class_entry = CG(active_class_entry); zend_op_array *orig_op_array = CG(active_op_array); @@ -6268,7 +6269,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /* if (is_method) { zend_bool has_body = stmt_ast != NULL; - zend_begin_method_decl(op_array, decl->name, has_body); + method_lcname = zend_begin_method_decl(op_array, decl->name, has_body); } else { zend_begin_func_decl(result, op_array, decl, toplevel); if (decl->kind == ZEND_AST_ARROW_FUNC) { @@ -6323,7 +6324,8 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /* if (is_method) { zend_check_magic_method_implementation( - CG(active_class_entry), (zend_function *) op_array, E_COMPILE_ERROR); + CG(active_class_entry), (zend_function *) op_array, method_lcname, E_COMPILE_ERROR); + zend_string_release_ex(method_lcname, 0); } /* put the implicit return on the really last line */ |