@@ -315,7 +315,9 @@ void zend_enum_register_funcs(zend_class_entry *ce)
315315 cases_function -> scope = ce ;
316316 cases_function -> fn_flags = fn_flags ;
317317 cases_function -> arg_info = (zend_internal_arg_info * ) (arginfo_class_UnitEnum_cases + 1 );
318- zend_hash_add_ptr (& ce -> function_table , ZSTR_KNOWN (ZEND_STR_CASES ), cases_function );
318+ if (!zend_hash_add_ptr (& ce -> function_table , ZSTR_KNOWN (ZEND_STR_CASES ), cases_function )) {
319+ zend_error_noreturn (E_COMPILE_ERROR , "Cannot redeclare %s::cases()" , ZSTR_VAL (ce -> name ));
320+ }
319321
320322 if (ce -> enum_backing_type != IS_UNDEF ) {
321323 zend_internal_function * from_function =
@@ -330,7 +332,10 @@ void zend_enum_register_funcs(zend_class_entry *ce)
330332 from_function -> num_args = 1 ;
331333 from_function -> required_num_args = 1 ;
332334 from_function -> arg_info = (zend_internal_arg_info * ) (arginfo_class_BackedEnum_from + 1 );
333- zend_hash_add_ptr (& ce -> function_table , ZSTR_KNOWN (ZEND_STR_FROM ), from_function );
335+ if (!zend_hash_add_ptr (& ce -> function_table , ZSTR_KNOWN (ZEND_STR_FROM ), from_function )) {
336+ zend_error_noreturn (E_COMPILE_ERROR ,
337+ "Cannot redeclare %s::from()" , ZSTR_VAL (ce -> name ));
338+ }
334339
335340 zend_internal_function * try_from_function =
336341 zend_arena_alloc (& CG (arena ), sizeof (zend_internal_function ));
@@ -344,8 +349,11 @@ void zend_enum_register_funcs(zend_class_entry *ce)
344349 try_from_function -> num_args = 1 ;
345350 try_from_function -> required_num_args = 1 ;
346351 try_from_function -> arg_info = (zend_internal_arg_info * ) (arginfo_class_BackedEnum_tryFrom + 1 );
347- zend_hash_add_ptr (
348- & ce -> function_table , ZSTR_KNOWN (ZEND_STR_TRYFROM_LOWERCASE ), try_from_function );
352+ if (!zend_hash_add_ptr (
353+ & ce -> function_table , ZSTR_KNOWN (ZEND_STR_TRYFROM_LOWERCASE ), try_from_function )) {
354+ zend_error_noreturn (E_COMPILE_ERROR ,
355+ "Cannot redeclare %s::tryFrom()" , ZSTR_VAL (ce -> name ));
356+ }
349357 }
350358}
351359
0 commit comments