# [RFC] Validation for abstract trait methods

- Thread: https://externals.io/message/108422
- Original archive: https://news-web.php.net/php.internals/108422
- Started by Nikita Popov on 2020-02-07T10:32:51+00:00
- Messages: 5
- RFC: Abstract trait method validation (Implemented (PHP 8.0)) — https://externals.io/rfc/abstract_trait_method_validation.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #108422 — Nikita Popov — 2020-02-07T10:32:51+00:00

URL: https://externals.io/message/108422#108422

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 — Nikita Popov — 2020-03-03T15:00:51+00:00

URL: https://externals.io/message/108422#108825 · In reply to: #108422

> 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 — Levi Morrison via internals — 2020-03-03T21:39:50+00:00

URL: https://externals.io/message/108422#108833 · In reply to: #108825

>
> 
>
> > […]
>
> 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 — Nikita Popov — 2020-03-03T21:56:47+00:00

URL: https://externals.io/message/108422#108834 · In reply to: #108833

On Tue, Mar 3, 2020 at 10:40 PM Levi Morrison <levi.morrison@datadoghq.com>
wrote:

> 
> > […]
> wrote:
> > […]
> for
> > […]
> reason
> > […]
>
> 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 — Nikita Popov — 2020-03-23T14:08:30+00:00

URL: https://externals.io/message/108422#109230 · In reply to: #108422

> 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
