Re: [RFC] [DISCUSSION] Ensure correct magic methods' signatures when typed
| From: | Claude Pache | Date: | Tue, 07 Apr 2020 10:55:56 +0000 |
| Subject: | Re: [RFC] [DISCUSSION] Ensure correct magic methods' signatures when typed | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109547@lists.php.net to get a copy of this message | ||
> Le 5 avr. 2020 à 16:01, Gabriel Caruso <carusogabriel34@gmail.com> a écrit :
>
> Hello, internals.
>
> Hereby you can find the RFC Document that I want to discuss as suggested
> via https://externals.io/message/109416 and
> https://externals.io/message/107990:
>
> https://wiki.php.net/rfc/magic-methods-signature
>
> Best regards,
>
> -- Gabriel Caruso
Hi,
Regarding __construct(), etc. Since those methods are not supposed to return anything, they ought to
accept the
void return pseudo-type in their signature, which means exactly that: “do
not return anything”. I consider that the current behaviour (i.e., not accepting the :
void signature) as a bug, and was very surprised when I stumbled on it.
------------
Also, I raise the following question:
Should omitted types be added implicitly? I.e., if I write: function __toString() { }
should the compiler interpret it as function __toString(): string { } ? (Currently, it
is not the case.)
Doing so would raise BC concerns for some, uh, creative uses of magic methods. On the other hand,
that may help to add progressively type informations on magic methods, since there is no need to
synchronise manually classes and subclasses (the compiler would do it automatically for you).
Concrete example here: https://3v4l.org/hTMvA <https://3v4l.org/hTMvA>
—Claude