@@ -5874,7 +5874,7 @@ void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_boo
5874
5874
}
5875
5875
/* }}} */
5876
5876
5877
- static void zend_begin_func_decl (znode * result , zend_op_array * op_array , zend_ast_decl * decl , zend_bool toplevel ) /* {{{ */
5877
+ static int zend_begin_func_decl (znode * result , zend_op_array * op_array , zend_ast_decl * decl , zend_bool toplevel ) /* {{{ */
5878
5878
{
5879
5879
zend_ast * params_ast = decl -> child [0 ];
5880
5880
zend_string * unqualified_name , * name , * lcname , * key ;
@@ -5914,12 +5914,10 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
5914
5914
do_bind_function_error (lcname , op_array , 1 );
5915
5915
}
5916
5916
zend_string_release_ex (lcname , 0 );
5917
- return ;
5917
+ return SUCCESS ;
5918
5918
}
5919
5919
5920
5920
key = zend_build_runtime_definition_key (lcname , decl -> lex_pos );
5921
- zend_hash_update_ptr (CG (function_table ), key , op_array );
5922
-
5923
5921
if (op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
5924
5922
opline = zend_emit_op_tmp (result , ZEND_DECLARE_LAMBDA_FUNCTION , NULL , NULL );
5925
5923
opline -> extended_value = zend_alloc_cache_slot ();
@@ -5934,6 +5932,8 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
5934
5932
zend_add_literal_string (& key );
5935
5933
}
5936
5934
zend_string_release_ex (lcname , 0 );
5935
+
5936
+ return zend_hash_add_ptr (CG (function_table ), key , op_array ) != NULL ? SUCCESS : FAILURE ;
5937
5937
}
5938
5938
/* }}} */
5939
5939
@@ -5979,7 +5979,13 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
5979
5979
zend_bool has_body = stmt_ast != NULL ;
5980
5980
zend_begin_method_decl (op_array , decl -> name , has_body );
5981
5981
} else {
5982
- zend_begin_func_decl (result , op_array , decl , toplevel );
5982
+ if (zend_begin_func_decl (result , op_array , decl , toplevel ) == FAILURE ) {
5983
+ /* A function with this RTD key is already registered.
5984
+ * Fail gracefully by reusing the existing function. */
5985
+ destroy_op_array (op_array );
5986
+ return ;
5987
+ }
5988
+
5983
5989
if (decl -> kind == ZEND_AST_ARROW_FUNC ) {
5984
5990
find_implicit_binds (& info , params_ast , stmt_ast );
5985
5991
compile_implicit_lexical_binds (& info , result , op_array );
0 commit comments