@@ -7126,7 +7126,7 @@ static uint32_t zend_add_dynamic_func_def(zend_op_array *def) {
7126
7126
return def_offset ;
7127
7127
}
7128
7128
7129
- static void zend_begin_func_decl (znode * result , zend_op_array * op_array , zend_ast_decl * decl , bool toplevel ) /* {{{ */
7129
+ static zend_string * zend_begin_func_decl (znode * result , zend_op_array * op_array , zend_ast_decl * decl , bool toplevel ) /* {{{ */
7130
7130
{
7131
7131
zend_string * unqualified_name , * name , * lcname ;
7132
7132
zend_op * opline ;
@@ -7157,11 +7157,7 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
7157
7157
7158
7158
zend_register_seen_symbol (lcname , ZEND_SYMBOL_FUNCTION );
7159
7159
if (toplevel ) {
7160
- if (UNEXPECTED (zend_hash_add_ptr (CG (function_table ), lcname , op_array ) == NULL )) {
7161
- do_bind_function_error (lcname , op_array , 1 );
7162
- }
7163
- zend_string_release_ex (lcname , 0 );
7164
- return ;
7160
+ return lcname ;
7165
7161
}
7166
7162
7167
7163
uint32_t func_ref = zend_add_dynamic_func_def (op_array );
@@ -7175,7 +7171,8 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
7175
7171
LITERAL_STR (opline -> op1 , zend_string_copy (lcname ));
7176
7172
opline -> op2 .num = func_ref ;
7177
7173
}
7178
- zend_string_release_ex (lcname , 0 );
7174
+
7175
+ return lcname ;
7179
7176
}
7180
7177
/* }}} */
7181
7178
@@ -7187,7 +7184,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
7187
7184
zend_ast * stmt_ast = decl -> child [2 ];
7188
7185
zend_ast * return_type_ast = decl -> child [3 ];
7189
7186
bool is_method = decl -> kind == ZEND_AST_METHOD ;
7190
- zend_string * method_lcname = NULL ;
7187
+ zend_string * lcname ;
7191
7188
7192
7189
zend_class_entry * orig_class_entry = CG (active_class_entry );
7193
7190
zend_op_array * orig_op_array = CG (active_op_array );
@@ -7219,9 +7216,9 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
7219
7216
7220
7217
if (is_method ) {
7221
7218
bool has_body = stmt_ast != NULL ;
7222
- method_lcname = zend_begin_method_decl (op_array , decl -> name , has_body );
7219
+ lcname = zend_begin_method_decl (op_array , decl -> name , has_body );
7223
7220
} else {
7224
- zend_begin_func_decl (result , op_array , decl , toplevel );
7221
+ lcname = zend_begin_func_decl (result , op_array , decl , toplevel );
7225
7222
if (decl -> kind == ZEND_AST_ARROW_FUNC ) {
7226
7223
find_implicit_binds (& info , params_ast , stmt_ast );
7227
7224
compile_implicit_lexical_binds (& info , result , op_array );
@@ -7264,7 +7261,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
7264
7261
}
7265
7262
7266
7263
zend_compile_params (params_ast , return_type_ast ,
7267
- is_method && zend_string_equals_literal (method_lcname , ZEND_TOSTRING_FUNC_NAME ) ? IS_STRING : 0 );
7264
+ is_method && zend_string_equals_literal (lcname , ZEND_TOSTRING_FUNC_NAME ) ? IS_STRING : 0 );
7268
7265
if (CG (active_op_array )-> fn_flags & ZEND_ACC_GENERATOR ) {
7269
7266
zend_mark_function_as_generator ();
7270
7267
zend_emit_op (NULL , ZEND_GENERATOR_CREATE , NULL , NULL );
@@ -7280,9 +7277,14 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
7280
7277
if (is_method ) {
7281
7278
CG (zend_lineno ) = decl -> start_lineno ;
7282
7279
zend_check_magic_method_implementation (
7283
- CG (active_class_entry ), (zend_function * ) op_array , method_lcname , E_COMPILE_ERROR );
7284
- zend_string_release_ex (method_lcname , 0 );
7280
+ CG (active_class_entry ), (zend_function * ) op_array , lcname , E_COMPILE_ERROR );
7281
+ } else if (toplevel ) {
7282
+ /* Only register the function after a successful compile */
7283
+ if (UNEXPECTED (zend_hash_add_ptr (CG (function_table ), lcname , op_array ) == NULL )) {
7284
+ do_bind_function_error (lcname , op_array , true);
7285
+ }
7285
7286
}
7287
+ zend_string_release_ex (lcname , 0 );
7286
7288
7287
7289
/* put the implicit return on the really last line */
7288
7290
CG (zend_lineno ) = decl -> end_lineno ;
0 commit comments