On Thu, 16 Apr 2020 at 16:22, Guilliam Xavier <guilliam.xav...@gmail.com> wrote:
> On Sun, Apr 5, 2020 at 4:02 PM Gabriel Caruso <carusogabrie...@gmail.com> > wrote: > > > > 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 > > Hello, > > Thank you, this seems a sensible thing to add. > > Just an interrogation: the following magic methods (from the > documentation) aren't mentioned at all in the RFC: > - `__sleep(): array` > - `__wakeup(): void` > - `__unserialize(array $data): void` > - (`__invoke` is basically untyped) > - `__set_state(array $properties): object` > - `__debugInfo(): array` > Is there a reason for leaving them out? > Related, the RFC mentions that `__unserialize` and `__toString` already > have a *runtime* check that they respectively return an `array` and a > `string` (when called), but why not check their signature (if typed) > at *compile time* too (i.e. make https://3v4l.org/ZPrVi an error)? > > Regards, > > -- > Guilliam Xavier > Hello Guilliam Magic methods not mentioned in the RFC won't be changed, that's why they aren't mentioned. The reason is either: - Isn't possible to add checks: the case of `__invoke` - They aren't really magic methods, but an extension method implementation (as far as I understood during the development of this RFC) `__unserialize` and `__serialize` should be possible to add these checks, I'll take a look in the implementation. About `__toString`: this check is already performed in PHP 8.0: https://3v4l.org/jIg7b/rfc#git-php-maste <https://3v4l.org/jIg7b/rfc#git-php-master>r