@@ -7321,6 +7321,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
7321
7321
RETURN_THROWS ();
7322
7322
}
7323
7323
7324
+ zend_attribute * delayed_target_validation = zend_get_attribute_str (
7325
+ attr -> attributes ,
7326
+ "delayedtargetvalidation" ,
7327
+ strlen ("delayedtargetvalidation" )
7328
+ );
7329
+
7324
7330
/* This code can be reached under one of three possible conditions:
7325
7331
* - the attribute is an internal attribute, and it had the target and
7326
7332
* and repetition validated already
@@ -7329,17 +7335,15 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
7329
7335
* #[DelayedTargetValidation]
7330
7336
* - the attribute is a user attribute, and neither target nor repetition
7331
7337
* have been validated.
7332
- *
7333
- * It is not worth checking for the presence of #[DelayedTargetValidation]
7334
- * to determine if we should run target validation for internal attributes;
7335
- * it is faster just to do the validation, which will always pass if the
7336
- * attribute is absent.
7337
7338
*/
7338
7339
uint32_t flags = zend_attribute_attribute_get_flags (marker , ce );
7339
7340
if (EG (exception )) {
7340
7341
RETURN_THROWS ();
7341
7342
}
7342
7343
7344
+ /* No harm in always running target validation, for internal attributes
7345
+ * with #[DelayedTargetValidation] it isn't necessary but will always
7346
+ * succeed. */
7343
7347
if (!(attr -> target & flags )) {
7344
7348
zend_string * location = zend_get_attribute_target_names (attr -> target );
7345
7349
zend_string * allowed = zend_get_attribute_target_names (flags );
@@ -7355,12 +7359,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
7355
7359
}
7356
7360
7357
7361
/* Run the delayed validator function for internal attributes */
7358
- if (ce -> type == ZEND_INTERNAL_CLASS ) {
7362
+ if (delayed_target_validation && ce -> type == ZEND_INTERNAL_CLASS ) {
7359
7363
zend_internal_attribute * config = zend_internal_attribute_get (attr -> data -> lcname );
7360
7364
if (config != NULL && config -> validator != NULL ) {
7361
7365
config -> validator (
7362
7366
attr -> data ,
7363
- attr -> target | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
7367
+ flags | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
7364
7368
attr -> scope
7365
7369
);
7366
7370
if (EG (exception )) {
0 commit comments