Skip to content

Fix GH-15731: Prevent #[AllowDynamicProperties] on enums #15733

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

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

DanielEScherzer
Copy link
Member

No description provided.

@devnexen
Copy link
Member

devnexen commented Sep 3, 2024

lgtm but prefer to see other people opinion, no rush it s not really a terrible bug :-)

@cmb69 cmb69 linked an issue Sep 3, 2024 that may be closed by this pull request
@@ -84,6 +84,11 @@ static void validate_allow_dynamic_properties(
ZSTR_VAL(scope->name)
);
}
if (scope->ce_flags & ZEND_ACC_ENUM) {
Copy link
Member

@kocsismate kocsismate Sep 4, 2024

Choose a reason for hiding this comment

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

The change looks good on its own but I'm wondering whether it isn't an oversight of the enum RFC that attributes targeting classes are allowed for enums? It looks like to me that we should(n't have) allow(ed) this, so the best course of action would be to add a new target for enums, and only allow the usage if it's set.

cc @iluuu1994

Copy link
Member

@iluuu1994 iluuu1994 Sep 4, 2024

Choose a reason for hiding this comment

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

It's not an oversight. From the RFC:

https://wiki.php.net/rfc/enumerations

Enums and cases may have attributes attached to them, like any other language construct. The TARGET_CLASS target filter will include Enums themselves.

Enums are special classes, just like interfaces, traits, etc.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I see it now.

Copy link
Member

Choose a reason for hiding this comment

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

@kocsismate Do you have a special use-case for TARGET_ENUM? We considered it back then but it never came up again, so I assume use-cases are limited.

Copy link
Member

Choose a reason for hiding this comment

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

Do you have a special use-case for TARGET_ENUM? We considered it back then but it never came up again, so I assume use-cases are limited.

No, I don't have any... I just proposed this in order to be able to retain the original behavior if we prevented the usage of attributes targeting classes for enums. But I realized that it would already be a possibly serious BC break since userland attributes have already been relying on the current behavior. Sorry for the noise!

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

LGTM, although this should probably target master. There's not much harm in adding the attribute atm, as it won't apply anyway.

@devnexen
Copy link
Member

devnexen commented Sep 4, 2024

LGTM, although this should probably target master.

@DanielEScherzer it might be best if you just update your other PR instead.

@DanielEScherzer DanielEScherzer changed the base branch from PHP-8.2 to master September 4, 2024 21:20
@DanielEScherzer
Copy link
Member Author

LGTM, although this should probably target master.

@DanielEScherzer it might be best if you just update your other PR instead.

Since the other PR has already merged, I have retargeted this to master

@devnexen devnexen merged commit 5a18279 into php:master Sep 4, 2024
8 checks passed
@devnexen
Copy link
Member

devnexen commented Sep 4, 2024

Thanks !

@DanielEScherzer DanielEScherzer deleted the allowdynamicproperties-enum branch September 4, 2024 23:08
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.

AllowDynamicProperties validation should error on enums
4 participants