Skip to content

Commit fd00c7c

Browse files
committed
Pass existing lcname to check_magic_method_implementation
1 parent 74f1547 commit fd00c7c

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

Zend/zend_API.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,17 +1958,13 @@ ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *mod
19581958
}
19591959
/* }}} */
19601960

1961-
ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type) /* {{{ */
1961+
ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, zend_string *lcname, int error_type) /* {{{ */
19621962
{
1963-
zend_string *lcname;
1964-
19651963
if (ZSTR_VAL(fptr->common.function_name)[0] != '_'
19661964
|| ZSTR_VAL(fptr->common.function_name)[1] != '_') {
19671965
return;
19681966
}
19691967

1970-
lcname = zend_string_tolower(fptr->common.function_name);
1971-
19721968
if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME) && fptr->common.num_args != 0) {
19731969
zend_error(error_type, "Destructor %s::%s() cannot take arguments", ZSTR_VAL(ce->name), ZEND_DESTRUCTOR_FUNC_NAME);
19741970
} 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,
20182014
} else if (zend_string_equals_literal(lcname, "__unserialize") && fptr->common.num_args != 1) {
20192015
zend_error(error_type, "Method %s::__unserialize() must take exactly 1 argument", ZSTR_VAL(ce->name));
20202016
}
2021-
2022-
zend_string_release_ex(lcname, 0);
20232017
}
20242018
/* }}} */
20252019

@@ -2237,7 +2231,8 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
22372231
reg_function = NULL;
22382232
}
22392233
if (reg_function) {
2240-
zend_check_magic_method_implementation(scope, reg_function, error_type);
2234+
zend_check_magic_method_implementation(
2235+
scope, reg_function, lowercase_name, error_type);
22412236
}
22422237
}
22432238
ptr++;

Zend/zend_API.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ ZEND_API int zend_startup_module_ex(zend_module_entry *module);
319319
ZEND_API int zend_startup_modules(void);
320320
ZEND_API void zend_collect_module_handlers(void);
321321
ZEND_API void zend_destroy_modules(void);
322-
ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type);
322+
ZEND_API void zend_check_magic_method_implementation(
323+
const zend_class_entry *ce, const zend_function *fptr, zend_string *lcname, int error_type);
323324

324325
ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
325326
ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);

Zend/zend_compile.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6070,7 +6070,7 @@ static void add_stringable_interface(zend_class_entry *ce) {
60706070
zend_string_init("stringable", sizeof("stringable") - 1, 0);
60716071
}
60726072

6073-
void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_bool has_body) /* {{{ */
6073+
zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_bool has_body) /* {{{ */
60746074
{
60756075
zend_class_entry *ce = CG(active_class_entry);
60766076
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
61636163
zend_check_magic_method_attr(fn_flags, ce, "__unserialize", 0);
61646164
}
61656165

6166-
zend_string_release_ex(lcname, 0);
6166+
return lcname;
61676167
}
61686168
/* }}} */
61696169

@@ -6236,6 +6236,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
62366236
zend_ast *stmt_ast = decl->child[2];
62376237
zend_ast *return_type_ast = decl->child[3];
62386238
zend_bool is_method = decl->kind == ZEND_AST_METHOD;
6239+
zend_string *method_lcname;
62396240

62406241
zend_class_entry *orig_class_entry = CG(active_class_entry);
62416242
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) /*
62686269

62696270
if (is_method) {
62706271
zend_bool has_body = stmt_ast != NULL;
6271-
zend_begin_method_decl(op_array, decl->name, has_body);
6272+
method_lcname = zend_begin_method_decl(op_array, decl->name, has_body);
62726273
} else {
62736274
zend_begin_func_decl(result, op_array, decl, toplevel);
62746275
if (decl->kind == ZEND_AST_ARROW_FUNC) {
@@ -6323,7 +6324,8 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
63236324

63246325
if (is_method) {
63256326
zend_check_magic_method_implementation(
6326-
CG(active_class_entry), (zend_function *) op_array, E_COMPILE_ERROR);
6327+
CG(active_class_entry), (zend_function *) op_array, method_lcname, E_COMPILE_ERROR);
6328+
zend_string_release_ex(method_lcname, 0);
63276329
}
63286330

63296331
/* put the implicit return on the really last line */

0 commit comments

Comments
 (0)