Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use attribute validator for assigning flags #19465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iluuu1994 wants to merge 2 commits into php:master
base: master
Choose a base branch
Loading
from iluuu1994:expand-attribute-validator

Conversation

Copy link
Member

@iluuu1994 iluuu1994 commented Aug 12, 2025

No description provided.

Copy link
Member Author

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

Copy link
Member

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

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

@DanielEScherzer DanielEScherzer Aug 15, 2025

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

iluuu1994 reacted with thumbs up emoji
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

@DanielEScherzer DanielEScherzer Aug 15, 2025

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) {

iluuu1994 reacted with thumbs up emoji
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

@DanielEScherzer DanielEScherzer Aug 15, 2025

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

Copy link
Member Author

iluuu1994 commented Aug 15, 2025
edited
Loading

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

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.

Copy link
Member

DanielEScherzer commented Aug 20, 2025
edited
Loading

#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

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
Reviewers

@DanielEScherzer DanielEScherzer DanielEScherzer left review comments

@TimWolla TimWolla Awaiting requested review from TimWolla

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /