@@ -7321,6 +7321,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73217321 RETURN_THROWS ();
73227322 }
73237323
7324+ zend_attribute * delayed_target_validation = zend_get_attribute_str (
7325+ attr -> attributes ,
7326+ "delayedtargetvalidation" ,
7327+ strlen ("delayedtargetvalidation" )
7328+ );
7329+
73247330 /* This code can be reached under one of three possible conditions:
73257331 * - the attribute is an internal attribute, and it had the target and
73267332 * and repetition validated already
@@ -7329,17 +7335,15 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73297335 * #[DelayedTargetValidation]
73307336 * - the attribute is a user attribute, and neither target nor repetition
73317337 * 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.
73377338 */
73387339 uint32_t flags = zend_attribute_attribute_get_flags (marker , ce );
73397340 if (EG (exception )) {
73407341 RETURN_THROWS ();
73417342 }
73427343
7344+ /* No harm in always running target validation, for internal attributes
7345+ * with #[DelayedTargetValidation] it isn't necessary but will always
7346+ * succeed. */
73437347 if (!(attr -> target & flags )) {
73447348 zend_string * location = zend_get_attribute_target_names (attr -> target );
73457349 zend_string * allowed = zend_get_attribute_target_names (flags );
@@ -7355,12 +7359,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73557359 }
73567360
73577361 /* 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 ) {
73597363 zend_internal_attribute * config = zend_internal_attribute_get (attr -> data -> lcname );
73607364 if (config != NULL && config -> validator != NULL ) {
73617365 config -> validator (
73627366 attr -> data ,
7363- attr -> target | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
7367+ flags | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
73647368 attr -> scope
73657369 );
73667370 if (EG (exception )) {
0 commit comments