@@ -847,7 +847,7 @@ static void zend_do_free(znode *op1) /* {{{ */
847
847
/* }}} */
848
848
849
849
850
- static char * zend_modifier_token_to_string (uint32_t token )
850
+ static const char * zend_modifier_token_to_string (uint32_t token )
851
851
{
852
852
switch (token ) {
853
853
case T_PUBLIC :
@@ -958,14 +958,22 @@ uint32_t zend_modifier_list_to_flags(zend_modifier_target target, zend_ast *modi
958
958
zend_ast_list * modifier_list = zend_ast_get_list (modifiers );
959
959
960
960
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 );
962
963
if (!new_flag ) {
963
964
return 0 ;
964
965
}
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 );
965
968
flags = zend_add_member_modifier (flags , new_flag , target );
966
969
if (!flags ) {
967
970
return 0 ;
968
971
}
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
+ }
969
977
}
970
978
971
979
return flags ;
@@ -1023,23 +1031,6 @@ uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag, zend_modifi
1023
1031
"Multiple access type modifiers are not allowed" , 0 );
1024
1032
return 0 ;
1025
1033
}
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
- }
1043
1034
if (target == ZEND_MODIFIER_TARGET_METHOD && (new_flags & ZEND_ACC_ABSTRACT ) && (new_flags & ZEND_ACC_FINAL )) {
1044
1035
zend_throw_exception (zend_ce_compile_error ,
1045
1036
"Cannot use the final modifier on an abstract method" , 0 );
0 commit comments