[RFC] Validation for abstract trait methods

  108422
February 7, 2020 10:32 nikita.ppv@gmail.com (Nikita Popov)
Hi internals,

I've sent a mail about this before, but as this turned into a bit of a
larger change (also allowing "abstract private" methods in traits) and
there's some backwards compatibility impact, I've created a proper RFC for
this:

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

Regards,
Nikita
  108825
March 3, 2020 15:00 nikita.ppv@gmail.com (Nikita Popov)
On Fri, Feb 7, 2020 at 11:32 AM Nikita Popov ppv@gmail.com> wrote:

> Hi internals, > > I've sent a mail about this before, but as this turned into a bit of a > larger change (also allowing "abstract private" methods in traits) and > there's some backwards compatibility impact, I've created a proper RFC for > this: > > https://wiki.php.net/rfc/abstract_trait_method_validation >
Based on Nicolas' feedback, I've adjusted the RFC to not validate the visibility of the method (only the signature and "static-ness"). The reason is outlined in the last paragraph of the Proposal section. With that done, I plan to open voting on this tomorrow, unless something new comes up. Regards, Nikita
  108833
March 3, 2020 21:39 internals@lists.php.net ("Levi Morrison via internals")
On Tue, Mar 3, 2020 at 8:01 AM Nikita Popov ppv@gmail.com> wrote:
> > On Fri, Feb 7, 2020 at 11:32 AM Nikita Popov ppv@gmail.com> wrote: > > > Hi internals, > > > > I've sent a mail about this before, but as this turned into a bit of a > > larger change (also allowing "abstract private" methods in traits) and > > there's some backwards compatibility impact, I've created a proper RFC for > > this: > > > > https://wiki.php.net/rfc/abstract_trait_method_validation > > > > Based on Nicolas' feedback, I've adjusted the RFC to not validate the > visibility of the method (only the signature and "static-ness"). The reason > is outlined in the last paragraph of the Proposal section. > > With that done, I plan to open voting on this tomorrow, unless something > new comes up. > > Regards, > Nikita
To clarify, this the signature enforcement is only applied to abstract methods that come from traits, correct? This code will remain valid? ``` trait CompareHelper { function compareTo($obj): bool {} } class C1 { use CompareHelper; function compareTo(self $obj) {} } ``` Notably, non-abstract methods will be able to change argument counts, their type, the return type, all without restriction. Correct? I don't particularly like code like this, but I've seen it out there on more than one occasion.
  108834
March 3, 2020 21:56 nikita.ppv@gmail.com (Nikita Popov)
On Tue, Mar 3, 2020 at 10:40 PM Levi Morrison morrison@datadoghq.com>
wrote:

> On Tue, Mar 3, 2020 at 8:01 AM Nikita Popov ppv@gmail.com> wrote: > > > > On Fri, Feb 7, 2020 at 11:32 AM Nikita Popov ppv@gmail.com> > wrote: > > > > > Hi internals, > > > > > > I've sent a mail about this before, but as this turned into a bit of a > > > larger change (also allowing "abstract private" methods in traits) and > > > there's some backwards compatibility impact, I've created a proper RFC > for > > > this: > > > > > > https://wiki.php.net/rfc/abstract_trait_method_validation > > > > > > > Based on Nicolas' feedback, I've adjusted the RFC to not validate the > > visibility of the method (only the signature and "static-ness"). The > reason > > is outlined in the last paragraph of the Proposal section. > > > > With that done, I plan to open voting on this tomorrow, unless something > > new comes up. > > > > Regards, > > Nikita > > To clarify, this the signature enforcement is only applied to abstract > methods that come from traits, correct? This code will remain valid? > > ``` > trait CompareHelper { > function compareTo($obj): bool {} > } > > class C1 { > use CompareHelper; > function compareTo(self $obj) {} > } > ``` > > Notably, non-abstract methods will be able to change argument counts, > their type, the return type, all without restriction. Correct? I don't > particularly like code like this, but I've seen it out there on more > than one occasion. >
That's right, this RFC is exclusively about abstract methods. No validation is performed for non-abstract methods. Nikita
  109230
March 23, 2020 14:08 nikita.ppv@gmail.com (Nikita Popov)
On Fri, Feb 7, 2020 at 11:32 AM Nikita Popov ppv@gmail.com> wrote:

> Hi internals, > > I've sent a mail about this before, but as this turned into a bit of a > larger change (also allowing "abstract private" methods in traits) and > there's some backwards compatibility impact, I've created a proper RFC for > this: > > https://wiki.php.net/rfc/abstract_trait_method_validation >
This RFC has been accepted unanimously with 52 votes in favor. Nikita