@@ -6079,7 +6079,7 @@ void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_boo
6079
6079
}
6080
6080
/* }}} */
6081
6081
6082
- static void zend_begin_func_decl (znode * result , zend_op_array * op_array , zend_ast_decl * decl , zend_bool toplevel ) /* {{{ */
6082
+ static int zend_begin_func_decl (znode * result , zend_op_array * op_array , zend_ast_decl * decl , zend_bool toplevel ) /* {{{ */
6083
6083
{
6084
6084
zend_string * unqualified_name , * name , * lcname , * key ;
6085
6085
zend_op * opline ;
@@ -6114,12 +6114,10 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
6114
6114
do_bind_function_error (lcname , op_array , 1 );
6115
6115
}
6116
6116
zend_string_release_ex (lcname , 0 );
6117
- return ;
6117
+ return SUCCESS ;
6118
6118
}
6119
6119
6120
6120
key = zend_build_runtime_definition_key (lcname , decl -> lex_pos );
6121
- zend_hash_update_ptr (CG (function_table ), key , op_array );
6122
-
6123
6121
if (op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
6124
6122
opline = zend_emit_op_tmp (result , ZEND_DECLARE_LAMBDA_FUNCTION , NULL , NULL );
6125
6123
opline -> extended_value = zend_alloc_cache_slot ();
@@ -6134,6 +6132,8 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
6134
6132
zend_add_literal_string (& key );
6135
6133
}
6136
6134
zend_string_release_ex (lcname , 0 );
6135
+
6136
+ return zend_hash_add_ptr (CG (function_table ), key , op_array ) != NULL ? SUCCESS : FAILURE ;
6137
6137
}
6138
6138
/* }}} */
6139
6139
@@ -6179,7 +6179,13 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
6179
6179
zend_bool has_body = stmt_ast != NULL ;
6180
6180
zend_begin_method_decl (op_array , decl -> name , has_body );
6181
6181
} else {
6182
- zend_begin_func_decl (result , op_array , decl , toplevel );
6182
+ if (zend_begin_func_decl (result , op_array , decl , toplevel ) == FAILURE ) {
6183
+ /* A function with this RTD key is already registered.
6184
+ * Fail gracefully by reusing the existing function. */
6185
+ destroy_op_array (op_array );
6186
+ return ;
6187
+ }
6188
+
6183
6189
if (decl -> kind == ZEND_AST_ARROW_FUNC ) {
6184
6190
find_implicit_binds (& info , params_ast , stmt_ast );
6185
6191
compile_implicit_lexical_binds (& info , result , op_array );
0 commit comments