Skip to content

Commit d91c08a

Browse files
Simplify reflection for non-debug builds
1 parent 7fa8cee commit d91c08a

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

ext/reflection/php_reflection.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7321,12 +7321,6 @@ 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-
73307324
/* This code can be reached under one of three possible conditions:
73317325
* - the attribute is an internal attribute, and it had the target and
73327326
* and repetition validated already
@@ -7360,15 +7354,23 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73607354
RETURN_THROWS();
73617355
}
73627356

7363-
/* Report the delayed validator error for internal attributes */
7364-
if (delayed_target_validation && ce->type == ZEND_INTERNAL_CLASS) {
7365-
zend_string *error = attr->data->validation_error;
7366-
if (error != NULL) {
7367-
zend_throw_exception(zend_ce_error, ZSTR_VAL(error), 0);
7368-
RETURN_THROWS();
7369-
}
7370-
} else {
7371-
ZEND_ASSERT(attr->data->validation_error == NULL);
7357+
if (attr->data->validation_error != NULL) {
7358+
/* Delayed validation errors should only be set for internal attributes. */
7359+
ZEND_ASSERT(ce->type == ZEND_INTERNAL_CLASS);
7360+
/* Delayed validation errors should only be set when
7361+
* #[\DelayedTargetValidation] is used. Searching for the attribute is
7362+
* more expensive than just an assertion and so we don't worry about it
7363+
* for non-debug builds. See discussion on GH-18817. */
7364+
#if ZEND_DEBUG
7365+
zend_attribute *delayed_target_validation = zend_get_attribute_str(
7366+
attr->attributes,
7367+
"delayedtargetvalidation",
7368+
strlen("delayedtargetvalidation")
7369+
);
7370+
ZEND_ASSERT(delayed_target_validation != NULL);
7371+
#endif
7372+
zend_throw_exception(zend_ce_error, ZSTR_VAL(attr->data->validation_error), 0);
7373+
RETURN_THROWS();
73727374
}
73737375

73747376
/* Repetition validation is done even if #[DelayedTargetValidation] is used

0 commit comments

Comments
 (0)