Skip to content

Commit cda97e7

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 4c372ec + 6bd8f40 commit cda97e7

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

Zend/zend_compile.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7272,7 +7272,7 @@ static uint32_t zend_add_dynamic_func_def(zend_op_array *def) {
72727272
return def_offset;
72737273
}
72747274

7275-
static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_ast_decl *decl, bool toplevel) /* {{{ */
7275+
static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_ast_decl *decl, bool toplevel) /* {{{ */
72767276
{
72777277
zend_string *unqualified_name, *name, *lcname;
72787278
zend_op *opline;
@@ -7306,23 +7306,20 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
73067306
if (UNEXPECTED(zend_hash_add_ptr(CG(function_table), lcname, op_array) == NULL)) {
73077307
do_bind_function_error(lcname, op_array, 1);
73087308
}
7309-
zend_observer_function_declared_notify(op_array, lcname);
7310-
zend_string_release_ex(lcname, 0);
7311-
return;
7312-
}
7313-
7314-
uint32_t func_ref = zend_add_dynamic_func_def(op_array);
7315-
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
7316-
opline = zend_emit_op_tmp(result, ZEND_DECLARE_LAMBDA_FUNCTION, NULL, NULL);
7317-
opline->op2.num = func_ref;
73187309
} else {
7319-
opline = get_next_op();
7320-
opline->opcode = ZEND_DECLARE_FUNCTION;
7321-
opline->op1_type = IS_CONST;
7322-
LITERAL_STR(opline->op1, zend_string_copy(lcname));
7323-
opline->op2.num = func_ref;
7310+
uint32_t func_ref = zend_add_dynamic_func_def(op_array);
7311+
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
7312+
opline = zend_emit_op_tmp(result, ZEND_DECLARE_LAMBDA_FUNCTION, NULL, NULL);
7313+
opline->op2.num = func_ref;
7314+
} else {
7315+
opline = get_next_op();
7316+
opline->opcode = ZEND_DECLARE_FUNCTION;
7317+
opline->op1_type = IS_CONST;
7318+
LITERAL_STR(opline->op1, zend_string_copy(lcname));
7319+
opline->op2.num = func_ref;
7320+
}
73247321
}
7325-
zend_string_release_ex(lcname, 0);
7322+
return lcname;
73267323
}
73277324
/* }}} */
73287325

@@ -7334,7 +7331,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
73347331
zend_ast *stmt_ast = decl->child[2];
73357332
zend_ast *return_type_ast = decl->child[3];
73367333
bool is_method = decl->kind == ZEND_AST_METHOD;
7337-
zend_string *method_lcname = NULL;
7334+
zend_string *lcname = NULL;
73387335

73397336
zend_class_entry *orig_class_entry = CG(active_class_entry);
73407337
zend_op_array *orig_op_array = CG(active_op_array);
@@ -7363,9 +7360,9 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
73637360

73647361
if (is_method) {
73657362
bool has_body = stmt_ast != NULL;
7366-
method_lcname = zend_begin_method_decl(op_array, decl->name, has_body);
7363+
lcname = zend_begin_method_decl(op_array, decl->name, has_body);
73677364
} else {
7368-
zend_begin_func_decl(result, op_array, decl, toplevel);
7365+
lcname = zend_begin_func_decl(result, op_array, decl, toplevel);
73697366
if (decl->kind == ZEND_AST_ARROW_FUNC) {
73707367
find_implicit_binds(&info, params_ast, stmt_ast);
73717368
compile_implicit_lexical_binds(&info, result, op_array);
@@ -7408,7 +7405,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
74087405
}
74097406

74107407
zend_compile_params(params_ast, return_type_ast,
7411-
is_method && zend_string_equals_literal(method_lcname, ZEND_TOSTRING_FUNC_NAME) ? IS_STRING : 0);
7408+
is_method && zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME) ? IS_STRING : 0);
74127409
if (CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) {
74137410
zend_mark_function_as_generator();
74147411
zend_emit_op(NULL, ZEND_GENERATOR_CREATE, NULL, NULL);
@@ -7437,8 +7434,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
74377434
if (is_method) {
74387435
CG(zend_lineno) = decl->start_lineno;
74397436
zend_check_magic_method_implementation(
7440-
CG(active_class_entry), (zend_function *) op_array, method_lcname, E_COMPILE_ERROR);
7441-
zend_string_release_ex(method_lcname, 0);
7437+
CG(active_class_entry), (zend_function *) op_array, lcname, E_COMPILE_ERROR);
74427438
}
74437439

74447440
/* put the implicit return on the really last line */
@@ -7453,6 +7449,12 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
74537449
/* Pop the loop variable stack separator */
74547450
zend_stack_del_top(&CG(loop_var_stack));
74557451

7452+
if (toplevel) {
7453+
zend_observer_function_declared_notify(op_array, lcname);
7454+
}
7455+
7456+
zend_string_release_ex(lcname, 0);
7457+
74567458
CG(active_op_array) = orig_op_array;
74577459
CG(active_class_entry) = orig_class_entry;
74587460
}

0 commit comments

Comments
 (0)