@@ -7305,6 +7305,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
7305
7305
RETURN_THROWS ();
7306
7306
}
7307
7307
7308
+ zend_attribute * delayed_target_validation = zend_get_attribute_str (
7309
+ attr -> attributes ,
7310
+ "delayedtargetvalidation" ,
7311
+ strlen ("delayedtargetvalidation" )
7312
+ );
7313
+
7308
7314
/* This code can be reached under one of three possible conditions:
7309
7315
* - the attribute is an internal attribute, and it had the target and
7310
7316
* and repetition validated already
@@ -7313,17 +7319,15 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
7313
7319
* #[DelayedTargetValidation]
7314
7320
* - the attribute is a user attribute, and neither target nor repetition
7315
7321
* have been validated.
7316
- *
7317
- * It is not worth checking for the presence of #[DelayedTargetValidation]
7318
- * to determine if we should run target validation for internal attributes;
7319
- * it is faster just to do the validation, which will always pass if the
7320
- * attribute is absent.
7321
7322
*/
7322
7323
uint32_t flags = zend_attribute_attribute_get_flags (marker , ce );
7323
7324
if (EG (exception )) {
7324
7325
RETURN_THROWS ();
7325
7326
}
7326
7327
7328
+ /* No harm in always running target validation, for internal attributes
7329
+ * with #[DelayedTargetValidation] it isn't necessary but will always
7330
+ * succeed. */
7327
7331
if (!(attr -> target & flags )) {
7328
7332
zend_string * location = zend_get_attribute_target_names (attr -> target );
7329
7333
zend_string * allowed = zend_get_attribute_target_names (flags );
@@ -7339,12 +7343,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
7339
7343
}
7340
7344
7341
7345
/* Run the delayed validator function for internal attributes */
7342
- if (ce -> type == ZEND_INTERNAL_CLASS ) {
7346
+ if (delayed_target_validation && ce -> type == ZEND_INTERNAL_CLASS ) {
7343
7347
zend_internal_attribute * config = zend_internal_attribute_get (attr -> data -> lcname );
7344
7348
if (config != NULL && config -> validator != NULL ) {
7345
7349
config -> validator (
7346
7350
attr -> data ,
7347
- attr -> target | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
7351
+ flags | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
7348
7352
attr -> scope
7349
7353
);
7350
7354
if (EG (exception )) {
0 commit comments