@@ -847,7 +847,7 @@ static void zend_do_free(znode *op1) /* {{{ */
847847/* }}} */
848848
849849
850- static char * zend_modifier_token_to_string (uint32_t token )
850+ static const char * zend_modifier_token_to_string (uint32_t token )
851851{
852852 switch (token ) {
853853 case T_PUBLIC :
@@ -958,14 +958,22 @@ uint32_t zend_modifier_list_to_flags(zend_modifier_target target, zend_ast *modi
958958 zend_ast_list * modifier_list = zend_ast_get_list (modifiers );
959959
960960 for (uint32_t i = 0 ; i < modifier_list -> children ; i ++ ) {
961- uint32_t new_flag = zend_modifier_token_to_flag (target , (uint32_t ) Z_LVAL_P (zend_ast_get_zval (modifier_list -> child [i ])));
961+ uint32_t token = (uint32_t ) Z_LVAL_P (zend_ast_get_zval (modifier_list -> child [i ]));
962+ uint32_t new_flag = zend_modifier_token_to_flag (target , token );
962963 if (!new_flag ) {
963964 return 0 ;
964965 }
966+ /* Don't error immediately for duplicate flags, we want to prioritize the errors from zend_add_member_modifier(). */
967+ bool duplicate_flag = (flags & new_flag );
965968 flags = zend_add_member_modifier (flags , new_flag , target );
966969 if (!flags ) {
967970 return 0 ;
968971 }
972+ if (duplicate_flag ) {
973+ zend_throw_exception_ex (zend_ce_compile_error , 0 ,
974+ "Multiple %s modifiers are not allowed" , zend_modifier_token_to_string (token ));
975+ return 0 ;
976+ }
969977 }
970978
971979 return flags ;
@@ -1023,23 +1031,6 @@ uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag, zend_modifi
10231031 "Multiple access type modifiers are not allowed" , 0 );
10241032 return 0 ;
10251033 }
1026- if ((flags & ZEND_ACC_ABSTRACT ) && (new_flag & ZEND_ACC_ABSTRACT )) {
1027- zend_throw_exception (zend_ce_compile_error , "Multiple abstract modifiers are not allowed" , 0 );
1028- return 0 ;
1029- }
1030- if ((flags & ZEND_ACC_STATIC ) && (new_flag & ZEND_ACC_STATIC )) {
1031- zend_throw_exception (zend_ce_compile_error , "Multiple static modifiers are not allowed" , 0 );
1032- return 0 ;
1033- }
1034- if ((flags & ZEND_ACC_FINAL ) && (new_flag & ZEND_ACC_FINAL )) {
1035- zend_throw_exception (zend_ce_compile_error , "Multiple final modifiers are not allowed" , 0 );
1036- return 0 ;
1037- }
1038- if ((flags & ZEND_ACC_READONLY ) && (new_flag & ZEND_ACC_READONLY )) {
1039- zend_throw_exception (zend_ce_compile_error ,
1040- "Multiple readonly modifiers are not allowed" , 0 );
1041- return 0 ;
1042- }
10431034 if (target == ZEND_MODIFIER_TARGET_METHOD && (new_flags & ZEND_ACC_ABSTRACT ) && (new_flags & ZEND_ACC_FINAL )) {
10441035 zend_throw_exception (zend_ce_compile_error ,
10451036 "Cannot use the final modifier on an abstract method" , 0 );
0 commit comments