@@ -5934,11 +5934,12 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
5934
5934
return ;
5935
5935
}
5936
5936
5937
- key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
5938
- if (!zend_hash_add_ptr (CG (function_table ), key , op_array )) {
5939
- zend_error_noreturn (E_ERROR ,
5940
- "Runtime definition key collision for function %s. This is a bug" , ZSTR_VAL (name ));
5941
- }
5937
+ /* Generate RTD keys until we find one that isn't in use yet. */
5938
+ key = NULL ;
5939
+ do {
5940
+ zend_tmp_string_release (key );
5941
+ key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
5942
+ } while (!zend_hash_add_ptr (CG (function_table ), key , op_array ));
5942
5943
5943
5944
if (op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
5944
5945
opline = zend_emit_op_tmp (result , ZEND_DECLARE_LAMBDA_FUNCTION , NULL , NULL );
@@ -6404,8 +6405,15 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6404
6405
6405
6406
zend_register_seen_symbol (lcname , ZEND_SYMBOL_CLASS );
6406
6407
} else {
6407
- name = zend_generate_anon_class_name (decl -> start_lineno );
6408
- lcname = zend_string_tolower (name );
6408
+ /* Find an anon class name that is not in use yet. */
6409
+ name = NULL ;
6410
+ lcname = NULL ;
6411
+ do {
6412
+ zend_tmp_string_release (name );
6413
+ zend_tmp_string_release (lcname );
6414
+ name = zend_generate_anon_class_name (decl -> start_lineno );
6415
+ lcname = zend_string_tolower (name );
6416
+ } while (zend_hash_exists (CG (class_table ), lcname ));
6409
6417
}
6410
6418
lcname = zend_new_interned_string (lcname );
6411
6419
@@ -6562,18 +6570,20 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6562
6570
opline -> result_type = IS_VAR ;
6563
6571
opline -> result .var = get_temporary_variable ();
6564
6572
if (!zend_hash_add_ptr (CG (class_table ), lcname , ce )) {
6573
+ /* We checked above that the class name is not used. This really shouldn't happen. */
6565
6574
zend_error_noreturn (E_ERROR ,
6566
6575
"Runtime definition key collision for %s. This is a bug" , ZSTR_VAL (name ));
6567
6576
}
6568
6577
} else {
6569
- zend_string * key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
6578
+ /* Generate RTD keys until we find one that isn't in use yet. */
6579
+ zend_string * key = NULL ;
6580
+ do {
6581
+ zend_tmp_string_release (key );
6582
+ key = zend_build_runtime_definition_key (lcname , decl -> start_lineno );
6583
+ } while (!zend_hash_add_ptr (CG (class_table ), key , ce ));
6570
6584
6571
6585
/* RTD key is placed after lcname literal in op1 */
6572
6586
zend_add_literal_string (& key );
6573
- if (!zend_hash_add_ptr (CG (class_table ), key , ce )) {
6574
- zend_error_noreturn (E_ERROR ,
6575
- "Runtime definition key collision for class %s. This is a bug" , ZSTR_VAL (name ));
6576
- }
6577
6587
6578
6588
opline -> opcode = ZEND_DECLARE_CLASS ;
6579
6589
if (extends_ast && toplevel
0 commit comments