@@ -7468,7 +7468,7 @@ static bool zend_is_valid_default_value(zend_type type, zval *value)
7468
7468
}
7469
7469
7470
7470
static void zend_compile_attributes (
7471
- HashTable * * attributes , zend_ast * ast , uint32_t offset , uint32_t target , uint32_t promoted
7471
+ HashTable * * attributes , zend_ast * ast , uint32_t offset , uint32_t target_type , uint32_t promoted , void * target
7472
7472
) /* {{{ */ {
7473
7473
zend_attribute * attr ;
7474
7474
zend_internal_attribute * config ;
@@ -7502,7 +7502,7 @@ static void zend_compile_attributes(
7502
7502
zend_string_release (lcname );
7503
7503
7504
7504
/* Exclude internal attributes that do not match on promoted properties. */
7505
- if (config && !(target & (config -> flags & ZEND_ATTRIBUTE_TARGET_ALL ))) {
7505
+ if (config && !(target_type & (config -> flags & ZEND_ATTRIBUTE_TARGET_ALL ))) {
7506
7506
if (promoted & (config -> flags & ZEND_ATTRIBUTE_TARGET_ALL )) {
7507
7507
zend_string_release (name );
7508
7508
continue ;
@@ -7560,8 +7560,8 @@ static void zend_compile_attributes(
7560
7560
continue ;
7561
7561
}
7562
7562
7563
- if (!(target & (config -> flags & ZEND_ATTRIBUTE_TARGET_ALL ))) {
7564
- zend_string * location = zend_get_attribute_target_names (target );
7563
+ if (!(target_type & (config -> flags & ZEND_ATTRIBUTE_TARGET_ALL ))) {
7564
+ zend_string * location = zend_get_attribute_target_names (target_type );
7565
7565
zend_string * allowed = zend_get_attribute_target_names (config -> flags );
7566
7566
7567
7567
zend_error_noreturn (E_ERROR , "Attribute \"%s\" cannot target %s (allowed targets: %s)" ,
@@ -7575,8 +7575,9 @@ static void zend_compile_attributes(
7575
7575
}
7576
7576
}
7577
7577
7578
- if (config -> validator != NULL ) {
7579
- config -> validator (attr , target , CG (active_class_entry ));
7578
+ /* target is NULL for global constants at compile-time. Validator will be called at runtime. */
7579
+ if (config -> validator != NULL && target ) {
7580
+ config -> validator (attr , target_type , CG (active_class_entry ), target , offset );
7580
7581
}
7581
7582
} ZEND_HASH_FOREACH_END ();
7582
7583
}
@@ -7773,13 +7774,6 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
7773
7774
arg_info -> name = zend_string_copy (name );
7774
7775
arg_info -> type = (zend_type ) ZEND_TYPE_INIT_NONE (0 );
7775
7776
7776
- if (attributes_ast ) {
7777
- zend_compile_attributes (
7778
- & op_array -> attributes , attributes_ast , i + 1 , ZEND_ATTRIBUTE_TARGET_PARAMETER ,
7779
- is_promoted ? ZEND_ATTRIBUTE_TARGET_PROPERTY : 0
7780
- );
7781
- }
7782
-
7783
7777
bool forced_allow_nullable = false;
7784
7778
if (type_ast ) {
7785
7779
uint32_t default_type = * default_ast_ptr ? Z_TYPE (default_node .u .constant ) : IS_UNDEF ;
@@ -7835,6 +7829,13 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
7835
7829
zval_ptr_dtor (& default_node .u .constant );
7836
7830
}
7837
7831
7832
+ if (attributes_ast ) {
7833
+ zend_compile_attributes (
7834
+ & op_array -> attributes , attributes_ast , i + 1 , ZEND_ATTRIBUTE_TARGET_PARAMETER ,
7835
+ is_promoted ? ZEND_ATTRIBUTE_TARGET_PROPERTY : 0 , op_array
7836
+ );
7837
+ }
7838
+
7838
7839
opline = zend_emit_op (NULL , opcode , NULL , & default_node );
7839
7840
SET_NODE (opline -> result , & var_node );
7840
7841
opline -> op1 .num = i + 1 ;
@@ -7917,12 +7918,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
7917
7918
}
7918
7919
if (attributes_ast ) {
7919
7920
zend_compile_attributes (
7920
- & prop -> attributes , attributes_ast , 0 , ZEND_ATTRIBUTE_TARGET_PROPERTY , ZEND_ATTRIBUTE_TARGET_PARAMETER );
7921
-
7922
- zend_attribute * override_attribute = zend_get_attribute_str (prop -> attributes , "override" , sizeof ("override" )- 1 );
7923
- if (override_attribute ) {
7924
- prop -> flags |= ZEND_ACC_OVERRIDE ;
7925
- }
7921
+ & prop -> attributes , attributes_ast , 0 , ZEND_ATTRIBUTE_TARGET_PROPERTY , ZEND_ATTRIBUTE_TARGET_PARAMETER , prop );
7926
7922
}
7927
7923
}
7928
7924
}
@@ -8429,37 +8425,7 @@ static zend_op_array *zend_compile_func_decl_ex(
8429
8425
target = ZEND_ATTRIBUTE_TARGET_METHOD ;
8430
8426
}
8431
8427
8432
- zend_compile_attributes (& op_array -> attributes , decl -> child [4 ], 0 , target , 0 );
8433
-
8434
- zend_attribute * override_attribute = zend_get_attribute_str (
8435
- op_array -> attributes ,
8436
- "override" ,
8437
- sizeof ("override" )- 1
8438
- );
8439
-
8440
- if (override_attribute ) {
8441
- op_array -> fn_flags |= ZEND_ACC_OVERRIDE ;
8442
- }
8443
-
8444
- zend_attribute * deprecated_attribute = zend_get_attribute_str (
8445
- op_array -> attributes ,
8446
- "deprecated" ,
8447
- sizeof ("deprecated" )- 1
8448
- );
8449
-
8450
- if (deprecated_attribute ) {
8451
- op_array -> fn_flags |= ZEND_ACC_DEPRECATED ;
8452
- }
8453
-
8454
- zend_attribute * nodiscard_attribute = zend_get_attribute_str (
8455
- op_array -> attributes ,
8456
- "nodiscard" ,
8457
- sizeof ("nodiscard" )- 1
8458
- );
8459
-
8460
- if (nodiscard_attribute ) {
8461
- op_array -> fn_flags |= ZEND_ACC_NODISCARD ;
8462
- }
8428
+ zend_compile_attributes (& op_array -> attributes , decl -> child [4 ], 0 , target , 0 , op_array );
8463
8429
}
8464
8430
8465
8431
/* Do not leak the class scope into free standing functions, even if they are dynamically
@@ -8901,12 +8867,7 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
8901
8867
}
8902
8868
8903
8869
if (attr_ast ) {
8904
- zend_compile_attributes (& info -> attributes , attr_ast , 0 , ZEND_ATTRIBUTE_TARGET_PROPERTY , 0 );
8905
-
8906
- zend_attribute * override_attribute = zend_get_attribute_str (info -> attributes , "override" , sizeof ("override" )- 1 );
8907
- if (override_attribute ) {
8908
- info -> flags |= ZEND_ACC_OVERRIDE ;
8909
- }
8870
+ zend_compile_attributes (& info -> attributes , attr_ast , 0 , ZEND_ATTRIBUTE_TARGET_PROPERTY , 0 , info );
8910
8871
}
8911
8872
8912
8873
CG (context ).active_property_info_name = old_active_property_info_name ;
@@ -8983,17 +8944,7 @@ static void zend_compile_class_const_decl(zend_ast *ast, uint32_t flags, zend_as
8983
8944
c = zend_declare_typed_class_constant (ce , name , & value_zv , flags , doc_comment , type );
8984
8945
8985
8946
if (attr_ast ) {
8986
- zend_compile_attributes (& c -> attributes , attr_ast , 0 , ZEND_ATTRIBUTE_TARGET_CLASS_CONST , 0 );
8987
-
8988
- zend_attribute * deprecated = zend_get_attribute_str (c -> attributes , "deprecated" , sizeof ("deprecated" )- 1 );
8989
-
8990
- if (deprecated ) {
8991
- ZEND_CLASS_CONST_FLAGS (c ) |= ZEND_ACC_DEPRECATED ;
8992
- /* For deprecated constants, we need to flag the zval for recursion
8993
- * detection. Make sure the zval is separated out of shm. */
8994
- ce -> ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS ;
8995
- ce -> ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED ;
8996
- }
8947
+ zend_compile_attributes (& c -> attributes , attr_ast , 0 , ZEND_ATTRIBUTE_TARGET_CLASS_CONST , 0 , c );
8997
8948
}
8998
8949
}
8999
8950
}
@@ -9263,7 +9214,7 @@ static void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel)
9263
9214
CG (active_class_entry ) = ce ;
9264
9215
9265
9216
if (decl -> child [3 ]) {
9266
- zend_compile_attributes (& ce -> attributes , decl -> child [3 ], 0 , ZEND_ATTRIBUTE_TARGET_CLASS , 0 );
9217
+ zend_compile_attributes (& ce -> attributes , decl -> child [3 ], 0 , ZEND_ATTRIBUTE_TARGET_CLASS , 0 , ce );
9267
9218
}
9268
9219
9269
9220
if (implements_ast ) {
@@ -9440,13 +9391,7 @@ static void zend_compile_enum_case(zend_ast *ast)
9440
9391
9441
9392
zend_ast * attr_ast = ast -> child [3 ];
9442
9393
if (attr_ast ) {
9443
- zend_compile_attributes (& c -> attributes , attr_ast , 0 , ZEND_ATTRIBUTE_TARGET_CLASS_CONST , 0 );
9444
-
9445
- zend_attribute * deprecated = zend_get_attribute_str (c -> attributes , "deprecated" , sizeof ("deprecated" )- 1 );
9446
-
9447
- if (deprecated ) {
9448
- ZEND_CLASS_CONST_FLAGS (c ) |= ZEND_ACC_DEPRECATED ;
9449
- }
9394
+ zend_compile_attributes (& c -> attributes , attr_ast , 0 , ZEND_ATTRIBUTE_TARGET_CLASS_CONST , 0 , c );
9450
9395
}
9451
9396
}
9452
9397
@@ -9660,7 +9605,7 @@ static void zend_compile_const_decl(zend_ast *ast) /* {{{ */
9660
9605
}
9661
9606
9662
9607
HashTable * attributes = NULL ;
9663
- zend_compile_attributes (& attributes , list -> child [1 ], 0 , ZEND_ATTRIBUTE_TARGET_CONST , 0 );
9608
+ zend_compile_attributes (& attributes , list -> child [1 ], 0 , ZEND_ATTRIBUTE_TARGET_CONST , 0 , NULL );
9664
9609
9665
9610
ZEND_ASSERT (last_op != NULL );
9666
9611
last_op -> opcode = ZEND_DECLARE_ATTRIBUTED_CONST ;
0 commit comments