]> granicus.if.org Git - php/commitdiff
Pass existing lcname to check_magic_method_implementation
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 27 Apr 2020 10:33:29 +0000 (12:33 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 27 Apr 2020 10:33:29 +0000 (12:33 +0200)
Zend/zend_API.c
Zend/zend_API.h
Zend/zend_compile.c

index 636cf703cc4271c4d68d88fe57282ec79867dc58..4aa76ca11103643ebb85f7b84e7f3006722d0e9d 100644 (file)
@@ -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++;
index 44c24bbca17ebf74793b32f2a74715351895f4ff..51353ad710c15e7d2d13c657a21608673a6d1c41 100644 (file)
@@ -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);
index 381a180f2953c97a0353b5bbbf422154dca6dca3..a83d4d3d180c11b53c850843efe970e3d8d4fb22 100644 (file)
@@ -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 */