Skip to content

Deprecate dynamic property creation with #[AllowDynamicProperties] escape hatch #7571

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

Closed
wants to merge 9 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Oct 12, 2021

This is a variant of #7390 that adds an #[AllowDynamicProperties] escape hatch, to explicitly allow using dynamic properties on a class without deprecation.

RFC: https://wiki.php.net/rfc/deprecate_dynamic_properties

TODO: Plaster #[AllowDynamicProperties] over large swathes of tests.

@nikic nikic force-pushed the deprecate-dynamic-props-2 branch from 10a0286 to a65dcea Compare October 12, 2021 09:06
@nikic nikic added the RFC label Oct 12, 2021
@nikic nikic force-pushed the deprecate-dynamic-props-2 branch 2 times, most recently from f90e5d6 to 1d6be97 Compare November 10, 2021 14:17
Copy link
Contributor

@TysonAndre TysonAndre left a comment

Choose a reason for hiding this comment

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

I had some minor comments/questions, easily fixable

@othercorey
Copy link
Contributor

While leaving the merits of this change to the voters, we had a technical question about this implementation.

Our framework uses dynamic properties to load models in a base class which all user app extend for each MVC + route connection. This is sometimes done with a trait in the child class and sometimes automatically in the base class.

Will this evaluate the AllowDynamicProperties permission from the child class only or will adding the attribute to the base class allow both child and base class to create dynamic properties?

@nikic
Copy link
Member Author

nikic commented Nov 16, 2021

While leaving the merits of this change to the voters, we had a technical question about this implementation.

Our framework uses dynamic properties to load models in a base class which all user app extend for each MVC + route connection. This is sometimes done with a trait in the child class and sometimes automatically in the base class.

Will this evaluate the AllowDynamicProperties permission from the child class only or will adding the attribute to the base class allow both child and base class to create dynamic properties?

The attribute also affects child classes. Quoting from the RFC:

Classes marked with #[AllowDynamicProperties] as well as their children can continue using dynamic properties without deprecation or removal.

If you add the attribute to the base class, then all classes that inherit from it can use dynamic properties as well. (You do need to extend from it -- using a trait with the attribute or implementing an interface with the attribute won't have an effect. And now that I say that, the implementation should probably explicitly forbid doing that.)

@uberbrady
Copy link

uberbrady commented Nov 25, 2021

(Comment deleted and replaced with message to php internals list: https://news-web.php.net/php.internals/116519 )

@nikic nikic mentioned this pull request Nov 26, 2021
2 tasks
@nikic nikic force-pushed the deprecate-dynamic-props-2 branch 2 times, most recently from f87f850 to 981a491 Compare November 26, 2021 10:34
@nikic nikic force-pushed the deprecate-dynamic-props-2 branch from 981a491 to 536d440 Compare November 26, 2021 10:58
@nikic
Copy link
Member Author

nikic commented Nov 26, 2021

Merged as 902d643.

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

Successfully merging this pull request may close these issues.

4 participants