@@ -7276,6 +7276,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
72767276 RETURN_THROWS ();
72777277 }
72787278
7279+ zend_attribute * delayed_target_validation = zend_get_attribute_str (
7280+ attr -> attributes ,
7281+ "delayedtargetvalidation" ,
7282+ strlen ("delayedtargetvalidation" )
7283+ );
7284+
72797285 /* This code can be reached under one of three possible conditions:
72807286 * - the attribute is an internal attribute, and it had the target and
72817287 * and repetition validated already
@@ -7284,17 +7290,15 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
72847290 * #[DelayedTargetValidation]
72857291 * - the attribute is a user attribute, and neither target nor repetition
72867292 * 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.
72927293 */
72937294 uint32_t flags = zend_attribute_attribute_get_flags (marker , ce );
72947295 if (EG (exception )) {
72957296 RETURN_THROWS ();
72967297 }
72977298
7299+ /* No harm in always running target validation, for internal attributes
7300+ * with #[DelayedTargetValidation] it isn't necessary but will always
7301+ * succeed. */
72987302 if (!(attr -> target & flags )) {
72997303 zend_string * location = zend_get_attribute_target_names (attr -> target );
73007304 zend_string * allowed = zend_get_attribute_target_names (flags );
@@ -7310,12 +7314,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73107314 }
73117315
73127316 /* 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 ) {
73147318 zend_internal_attribute * config = zend_internal_attribute_get (attr -> data -> lcname );
73157319 if (config != NULL && config -> validator != NULL ) {
73167320 config -> validator (
73177321 attr -> data ,
7318- attr -> target | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
7322+ flags | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ,
73197323 attr -> scope
73207324 );
73217325 if (EG (exception )) {
0 commit comments