Skip to content

Commit 8959bec

Browse files
Cleanup and tweaks
1 parent 205a14d commit 8959bec

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

UPGRADING

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,7 @@ PHP 8.5 UPGRADE NOTES
636636
========================================
637637

638638
- Core:
639-
. DelayedTargetValidation is an attribute that, when added, delays any errors
640-
from *other* internal attributes about being applied to invalid targets from
641-
compile-time to runtime.
639+
. DelayedTargetValidation attribute was added.
642640
RFC: https://wiki.php.net/rfc/delayedtargetvalidation_attribute
643641

644642
- Curl:

Zend/zend_attributes.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ static zend_string *validate_nodiscard(
217217
zend_attribute *attr, uint32_t target, zend_class_entry *scope)
218218
{
219219
ZEND_ASSERT(CG(in_compilation));
220-
zend_op_array *op_array = CG(active_op_array);
221220
const zend_string *prop_info_name = CG(context).active_property_info_name;
222221
if (prop_info_name == NULL) {
222+
zend_op_array *op_array = CG(active_op_array);
223223
op_array->fn_flags |= ZEND_ACC_NODISCARD;
224224
return NULL;
225225
}
@@ -524,12 +524,7 @@ ZEND_API zend_internal_attribute *zend_mark_internal_attribute(zend_class_entry
524524
if (zend_string_equals(attr->name, zend_ce_attribute->name)) {
525525
internal_attr = pemalloc(sizeof(zend_internal_attribute), 1);
526526
internal_attr->ce = ce;
527-
if (attr->argc == 0) {
528-
// Apply default of Attribute::TARGET_ALL
529-
internal_attr->flags = ZEND_ATTRIBUTE_TARGET_ALL;
530-
} else {
531-
internal_attr->flags = Z_LVAL(attr->args[0].value);
532-
}
527+
internal_attr->flags = Z_LVAL(attr->args[0].value);
533528
internal_attr->validator = NULL;
534529

535530
zend_string *lcname = zend_string_tolower_ex(ce->name, 1);

Zend/zend_attributes.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,5 @@ public function __construct(?string $message = null) {}
101101
/**
102102
* @strict-properties
103103
*/
104-
#[Attribute]
104+
#[Attribute(Attribute::TARGET_ALL)]
105105
final class DelayedTargetValidation {}

Zend/zend_attributes_arginfo.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Zend/zend_compile.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8536,8 +8536,9 @@ static zend_op_array *zend_compile_func_decl_ex(
85368536
if (op_array->fn_flags & ZEND_ACC_NODISCARD) {
85378537
/* ZEND_ACC_NODISCARD gets added by the attribute validator, but only
85388538
* if the method is not a hook; if it is a hook, then the validator
8539-
* should have either thrown an error or done nothing due to delayed
8540-
* target validation. */
8539+
* will have returned an error message, even if the error message was
8540+
* delayed with #[\DelayedTargetValidation] that ZEND_ACC_NODISCARD
8541+
* flag should not have been added. */
85418542
ZEND_ASSERT(!is_hook);
85428543

85438544
if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {

ext/reflection/php_reflection.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7331,8 +7331,10 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73317331
* - the attribute is an internal attribute, and it had the target and
73327332
* and repetition validated already
73337333
* - the attribute is an internal attribute and repetition was validated
7334-
* already, but the target was not validated due to the presence of
7335-
* #[DelayedTargetValidation]
7334+
* already, the internal validator might have been run if the target was
7335+
* correct, but any error would have been stored in
7336+
* `zend_attribute.validation_error` instead of being thrown due to the
7337+
* presence of #[DelayedTargetValidation]
73367338
* - the attribute is a user attribute, and neither target nor repetition
73377339
* have been validated.
73387340
*/
@@ -7358,7 +7360,7 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
73587360
RETURN_THROWS();
73597361
}
73607362

7361-
/* Run the delayed validator function for internal attributes */
7363+
/* Report the delayed validator error for internal attributes */
73627364
if (delayed_target_validation && ce->type == ZEND_INTERNAL_CLASS) {
73637365
zend_string *error = attr->data->validation_error;
73647366
if (error != NULL) {

0 commit comments

Comments
 (0)