Skip to content

Conversation

DanielEScherzer
Copy link
Member

Do not allow #[\Attribute] on traits, interfaces, enums, or abstract classes.

@DanielEScherzer
Copy link
Member Author

Targeting master for the same reason as #15733 did - this adds a new error where previously there wasn't one until you tried to make use of the attribute, at which point ReflectionAttribute::newInstance() would complain that you can't instantiate a trait/enum/interface/abstract class

@DanielEScherzer
Copy link
Member Author

I plan to merge this in a few days if there are no objections

@iluuu1994
Copy link
Member

The implementation looks correct. I'm not sure whether a short e-mail to internals@ is warranted, since this could break working code. https://3v4l.org/8Lih3#v8.4.10

@DanielEScherzer
Copy link
Member Author

Discussion at https://news-web.php.net/php.internals/128229

Do not allow #[\Attribute] on traits, interfaces, enums, or abstract classes.
@DanielEScherzer DanielEScherzer force-pushed the validate-attribute-attribute branch from 012b0f9 to ce3a659 Compare August 11, 2025 15:29
@DanielEScherzer DanielEScherzer merged commit c416191 into php:master Aug 11, 2025
9 checks passed
Copy link
Member

Choose a reason for hiding this comment

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

This should probably also be in UPGRADING, since it's technically a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, 6280dfc

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.

#[\Attribute] validation should error on trait/interface/enum/abstract class
3 participants