Skip to content

Conversation

iluuu1994
Copy link
Member

No description provided.

@iluuu1994
Copy link
Member Author

Oh, I just noticed this has significant overlap with #18817 (which I only went to review right after this PR).

@DanielEScherzer
Copy link
Member

I'd prefer to do #18817 first since that is for an RFC

@@ -70,7 +70,8 @@ typedef struct _zend_attribute {
typedef struct _zend_internal_attribute {
zend_class_entry *ce;
uint32_t flags;
void (*validator)(zend_attribute *attr, uint32_t target, zend_class_entry *scope);
/* Parameter offsets start at 1, everything else uses 0. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need both scope and target

if (target_type & (ZEND_ATTRIBUTE_TARGET_FUNCTION|ZEND_ATTRIBUTE_TARGET_METHOD)) {
zend_op_array *op_array = target;
op_array->fn_flags |= ZEND_ACC_DEPRECATED;
} else if (target_type & (ZEND_ATTRIBUTE_TARGET_CLASS_CONST)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (target_type & (ZEND_ATTRIBUTE_TARGET_CLASS_CONST)) {
} else if (target_type & ZEND_ATTRIBUTE_TARGET_CLASS_CONST) {

ZEND_CLASS_CONST_FLAGS(c) |= ZEND_ACC_DEPRECATED;
/* For deprecated constants, we need to flag the zval for recursion
* detection. Make sure the zval is separated out of shm. */
scope->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after removing the separate scope, can use

Suggested change
scope->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;
c->ce->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;

and similar for the removal of ZEND_ACC_CONSTANTS_UPDATED

@iluuu1994
Copy link
Member Author

iluuu1994 commented Aug 15, 2025

We should also move the ZEND_ACC_NODISCARD stuff from zend_compile.c into the validator, which I missed.

https://github.com/iluuu1994/php-src/blob/49b4e45d7fa0864707e00c51b771a8ecc2b6ae0c/Zend/zend_compile.c#L8479-L8498

@iluuu1994
Copy link
Member Author

I'd prefer to do #18817 first since that is for an RFC

That's ok with me. Though it makes your patch a bit more complicated, parts of it we might want to revert again.

@DanielEScherzer
Copy link
Member

DanielEScherzer commented Aug 20, 2025

#18817 has been merged, please rebase and then I'll take a look
Though if you wait until after #19045 there will already be a validator for #[\Deprecated] and you would just need to move the CONST_DEPRECATED addition there instead of creating the validator and everything

@iluuu1994
Copy link
Member Author

@DanielEScherzer That's fine too, I would just like to avoid rebasing multiple times. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants