@@ -6212,11 +6212,12 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
6212
6212
return ;
6213
6213
}
6214
6214
6215
- key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
6216
- if (!zend_hash_add_ptr (CG (function_table ), key , op_array )) {
6217
- zend_error_noreturn (E_ERROR ,
6218
- "Runtime definition key collision for function %s. This is a bug" , ZSTR_VAL (name ));
6219
- }
6215
+ /* Generate RTD keys until we find one that isn't in use yet. */
6216
+ key = NULL ;
6217
+ do {
6218
+ zend_tmp_string_release (key );
6219
+ key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
6220
+ } while (!zend_hash_add_ptr (CG (function_table ), key , op_array ));
6220
6221
6221
6222
if (op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
6222
6223
opline = zend_emit_op_tmp (result , ZEND_DECLARE_LAMBDA_FUNCTION , NULL , NULL );
@@ -6662,8 +6663,15 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, zend_bool toplevel) /
6662
6663
6663
6664
zend_register_seen_symbol (lcname , ZEND_SYMBOL_CLASS );
6664
6665
} else {
6665
- name = zend_generate_anon_class_name (decl );
6666
- lcname = zend_string_tolower (name );
6666
+ /* Find an anon class name that is not in use yet. */
6667
+ name = NULL ;
6668
+ lcname = NULL ;
6669
+ do {
6670
+ zend_tmp_string_release (name );
6671
+ zend_tmp_string_release (lcname );
6672
+ name = zend_generate_anon_class_name (decl );
6673
+ lcname = zend_string_tolower (name );
6674
+ } while (zend_hash_exists (CG (class_table ), lcname ));
6667
6675
}
6668
6676
lcname = zend_new_interned_string (lcname );
6669
6677
@@ -6795,18 +6803,20 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, zend_bool toplevel) /
6795
6803
opline -> extended_value = zend_alloc_cache_slot ();
6796
6804
zend_make_var_result (result , opline );
6797
6805
if (!zend_hash_add_ptr (CG (class_table ), lcname , ce )) {
6806
+ /* We checked above that the class name is not used. This really shouldn't happen. */
6798
6807
zend_error_noreturn (E_ERROR ,
6799
6808
"Runtime definition key collision for %s. This is a bug" , ZSTR_VAL (name ));
6800
6809
}
6801
6810
} else {
6802
- zend_string * key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
6811
+ /* Generate RTD keys until we find one that isn't in use yet. */
6812
+ zend_string * key = NULL ;
6813
+ do {
6814
+ zend_tmp_string_release (key );
6815
+ key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
6816
+ } while (!zend_hash_add_ptr (CG (class_table ), key , ce ));
6803
6817
6804
6818
/* RTD key is placed after lcname literal in op1 */
6805
6819
zend_add_literal_string (& key );
6806
- if (!zend_hash_add_ptr (CG (class_table ), key , ce )) {
6807
- zend_error_noreturn (E_ERROR ,
6808
- "Runtime definition key collision for class %s. This is a bug" , ZSTR_VAL (name ));
6809
- }
6810
6820
6811
6821
opline -> opcode = ZEND_DECLARE_CLASS ;
6812
6822
if (extends_ast && toplevel
0 commit comments