Skip to content

[RFC] Implement Property Capture for Anonymous Classes #11123

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IMSoP
Copy link
Contributor

@IMSoP IMSoP commented Apr 23, 2023

RFC: https://wiki.php.net/rfc/property-capture

Adds a "use" clause to anonymous class declarations, which allows capturing local variables by declaring them as properties in the class definition, and passing them into the constructor of each instance.

A new AST kind is used to track the list of properties to add and their modifiers (visibility, type, readonly, reference). This is then transformed into a constructor during compilation, piggy-backing on the implementation of Constructor Property Promotion, but using custom error messages and reflectable flags, so that a future implementation could work differently if necessary.

RFC: https://wiki.php.net/rfc/property-capture

Adds a "use" clause to anonymous class declarations, which
allows capturing local variables by declaring them as properties
in the class definition, and passing them into the constructor
of each instance.

A new AST kind is used to track the list of properties to add
and their modifiers (visibility, type, readonly, reference).
This is then transformed into a constructor during compilation,
piggy-backing on the implementation of Constructor Property
Promotion, but using custom error messages and reflectable
flags, so that a future implementation could work differently
if necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment