rfc:final_anonymous_classes
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:final_anonymous_classes [2023/11/15 17:38] – danog | rfc:final_anonymous_classes [2023/12/23 15:04] (current) – danog | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2023-11-15 | * Date: 2023-11-15 | ||
* Author: Daniil Gentili < | * Author: Daniil Gentili < | ||
- | * Status: | + | * Status: |
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC proposes to add support for final anonymous classes, //or// make all anonymous classes final by default, with or without the possibility to make them non-final. | + | This RFC proposes to add support for final anonymous classes. |
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes to either | + | This RFC proposes to add support for final anonymous classes. |
This should also allow some additional opcache optimizations, | This should also allow some additional opcache optimizations, | ||
- | Personally, I would have instead preferred the much cleaner approach of making all anonymous classes final by default, (preferrably) without offering the option to make them non-final. | + | Example syntax: |
- | However, I understand that this might be a little bit too restrictive for something that may have some valid usecases, even if extending anonymous classes currently requires some hack-ish workarounds with class_alias. | + | <code php> |
+ | $x = new final class {}; | ||
+ | </ | ||
- | Thus, this RFC includes three mutually exclusive proposals: | + | Extending a final anonymous class throws an error: |
- | - Add support for final anonymous classes ('' | + | <code php> |
- | | + | $x = new final class {}; |
- | - //OR// Make all anonymous classes final by default, provide an optional | + | class_alias($x:: |
+ | class aliasExtends extends alias {} | ||
+ | </code> | ||
+ | |||
+ | '' | ||
+ | Fatal error: Class aliasExtends cannot extend | ||
+ | '' | ||
- | As an extra proposal related to the last two options, possibly requiring a separate RFC, in the last two cases, it might be a good idea to also disallow the use of '' | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | In case proposal 2 is accepted, it will break existing code which extends from anonymous classes using '' | + | None. |
- | + | ||
- | In case proposal 2 is accepted //and// '' | + | |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 39: | Line 44: | ||
See Backward Incompatible Changes. | See Backward Incompatible Changes. | ||
- | |||
- | ===== Future Scope ===== | ||
- | |||
- | As an extra proposal related to the last two options, possibly requiring a separate RFC, in the last two cases, it might be a good idea to also disallow the use of '' | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | 2/3 required to accept. | + | 2/3 required to accept. Voting started on 2023-12-03 and will end on 2023-12-18 00:00 GMT. |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
+ | ===== Patches and Tests ===== | ||
- | 2/3 required to accept. | + | Final anonymous classes implementation: |
- | <doodle title="Make all anonymous classes final by default, without the option to make them non-final?" | + | ===== References ===== |
- | * Yes | + | |
- | * No | + | |
- | </ | + | |
+ | * Pull request discussion: https:// | ||
+ | * Internals discussion: https:// | ||
- | 2/3 required to accept. | ||
- | <doodle title="Make all anonymous classes final by default, with the option to make them non-final with an open keyword?" | + | ===== Rejected Features ===== |
- | * Yes | + | |
- | * No | + | |
- | </ | + | |
+ | After feedback received from Nikolas Grekas in the last [RFC] discussion thread (https:// | ||
- | ===== Patches and Tests ===== | + | < |
+ | Hi Daniil, | ||
- | Final anonymous classes | + | >> While I'm open to Proposal 1, which introduces final anonymous classes |
+ | >> without breaking BC, Proposals 2 and 3 are a different story. | ||
+ | >> In summary, I advocate for the RFC to focus on the non-BC-breaking option. | ||
+ | >> Let's maintain our commitment to stability and gradual evolution in PHP. | ||
+ | >> Cheers, | ||
+ | >> Nicolas | ||
- | ===== References ===== | + | > Agree with your points, just adding final anonymous classes seems the best solution to me, but given the interest in alternative solutions both in the pull request discussion, and in the previous mailing list thread, I think I'll leave the other options in the RFC, to see how the votes will go (I'm actually curious myself :). |
+ | > Regards, | ||
+ | > Daniil Gentili | ||
- | * Pull request discussion: https:// | + | I think this is a dangerous game. Breaking BC shouldn' |
- | * Internals discussion: https:// | + | |
+ | | ||
+ | </ | ||
+ | |||
+ | To be entirely honest, I'm a bit on the fence: on one hand, looking at code like '' | ||
+ | |||
+ | - Has a name (even if it's not immediately obvious) | ||
+ | - Can be referenced to using its name ('' | ||
+ | |||
+ | seems a tad bit too restrictive... | ||
+ | |||
+ | On the other hand, I also really don't like non-final classes, in all of my projects, I use CS rules that force all classes to either be abstract or final, because unfortunately, | ||
+ | |||
+ | Still, there are some useful patterns, mainly regarding testing and mocking, for example I use https:// | ||
+ | |||
+ | This is why I remain ambivalent about the options, as seen both in my emails and in the original text of the RFC: | ||
+ | |||
+ | Personally, I would have instead preferred the much cleaner approach of making all anonymous classes final by default, (preferrably) without offering the option to make them non-final. | ||
+ | |||
+ | However, I understand that this might be a little bit too restrictive for something that may have some valid usecases, even if extending anonymous classes currently requires some hack-ish workarounds with class_alias. | ||
+ | |||
+ | Thus, this RFC initially included three mutually exclusive proposals: | ||
+ | |||
+ | - Add support for final anonymous classes ('' | ||
+ | - //OR// Make all anonymous classes final by default, without the option to make them final (breaking change) | ||
+ | - //OR// Make all anonymous classes final by default, provide an optional '' | ||
+ | |||
+ | As an extra proposal related to the last two options, possibly requiring a separate RFC, in the last two cases, it might be a good idea to also disallow the use of '' |
rfc/final_anonymous_classes.1700069911.txt.gz · Last modified: 2023/11/15 17:38 by danog