@@ -7276,6 +7276,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
7276
7276
RETURN_THROWS ();
7277
7277
}
7278
7278
7279
+ zend_attribute * delayed_target_validation = zend_get_attribute_str (
7280
+ attr -> attributes ,
7281
+ "delayedtargetvalidation" ,
7282
+ strlen ("delayedtargetvalidation" )
7283
+ );
7284
+
7279
7285
/* This code can be reached under one of three possible conditions:
7280
7286
* - the attribute is an internal attribute, and it had the target and
7281
7287
* and repetition validated already
@@ -7284,17 +7290,15 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
7284
7290
* #[DelayedTargetValidation]
7285
7291
* - the attribute is a user attribute, and neither target nor repetition
7286
7292
* have been validated.
7287
- *
7288
- * It is not worth checking for the presence of #[DelayedTargetValidation]
7289
- * to determine if we should run target validation for internal attributes;
7290
- * it is faster just to do the validation, which will always pass if the
7291
- * attribute is absent.
7292
7293
*/
7293
7294
uint32_t flags = zend_attribute_attribute_get_flags (marker , ce );
7294
7295
if (EG (exception )) {
7295
7296
RETURN_THROWS ();
7296
7297
}
7297
7298
7299
+ /* No harm in always running target validation, for internal attributes
7300
+ * with #[DelayedTargetValidation] it isn't necessary but will always
7301
+ * succeed. */
7298
7302
if (!(attr -> target & flags )) {
7299
7303
zend_string * location = zend_get_attribute_target_names (attr -> target );
7300
7304
zend_string * allowed = zend_get_attribute_target_names (flags );
@@ -7310,12 +7314,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
7310
7314
}
7311
7315
7312
7316
/* Run the delayed validator function for internal attributes */
7313
- if (ce -> type == ZEND_INTERNAL_CLASS ) {
7317
+ if (delayed_target_validation && ce -> type == ZEND_INTERNAL_CLASS ) {
7314
7318
zend_internal_attribute * config = zend_internal_attribute_get (attr -> data -> lcname );
7315
7319
if (config != NULL && config -> validator != NULL ) {
7316
7320
config -> validator (
7317
7321
attr -> data ,
7318
- attr -> target | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
7322
+ flags | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
7319
7323
attr -> scope
7320
7324
);
7321
7325
if (EG (exception )) {
0 commit comments