Skip to content

Commit 2c43516

Browse files
Fix for reflection
1 parent 21505f2 commit 2c43516

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

ext/reflection/php_reflection.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7305,6 +7305,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73057305
RETURN_THROWS();
73067306
}
73077307

7308+
zend_attribute *delayed_target_validation = zend_get_attribute_str(
7309+
attr->attributes,
7310+
"delayedtargetvalidation",
7311+
strlen("delayedtargetvalidation")
7312+
);
7313+
73087314
/* This code can be reached under one of three possible conditions:
73097315
* - the attribute is an internal attribute, and it had the target and
73107316
* and repetition validated already
@@ -7313,17 +7319,15 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73137319
* #[DelayedTargetValidation]
73147320
* - the attribute is a user attribute, and neither target nor repetition
73157321
* 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.
73217322
*/
73227323
uint32_t flags = zend_attribute_attribute_get_flags(marker, ce);
73237324
if (EG(exception)) {
73247325
RETURN_THROWS();
73257326
}
73267327

7328+
/* No harm in always running target validation, for internal attributes
7329+
* with #[DelayedTargetValidation] it isn't necessary but will always
7330+
* succeed. */
73277331
if (!(attr->target & flags)) {
73287332
zend_string *location = zend_get_attribute_target_names(attr->target);
73297333
zend_string *allowed = zend_get_attribute_target_names(flags);
@@ -7339,12 +7343,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73397343
}
73407344

73417345
/* 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) {
73437347
zend_internal_attribute *config = zend_internal_attribute_get(attr->data->lcname);
73447348
if (config != NULL && config->validator != NULL) {
73457349
config->validator(
73467350
attr->data,
7347-
attr->target | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION,
7351+
flags | ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION,
73487352
attr->scope
73497353
);
73507354
if (EG(exception)) {

0 commit comments

Comments
 (0)