On Tue, 14 Apr 2020 at 15:24, Nicolas Grekas <nicolas.grekas+...@gmail.com> wrote:
> Hello Gabriel, > > >>> https://wiki.php.net/rfc/magic-methods-signature >> >> RFC and implementation have been updated. >> > > There are a few things I don't understand from the RFC, let me list from > the examples. > > > This RFC proposes to introduce the following signatures checks when > magic methods are typed: > > My general question is: what does this mean exactly? > > > > /** @return mixed */ > > Foo::__call(string $name, array $arguments); > > > /** @return mixed */ > > Foo::__callStatic(string $name, array $arguments); > > > /** @return mixed */ > > Foo::__get(string $name); > > > Does this mean we won't be allowed to declare __call($name, $arguments);? > > This looks against LSP to me. > > > > Foo::__clone(): void; > > > /** @param mixed $args */ > > Foo::__construct($args): void; > > > Foo::__destruct(): void; > > Is void going to be mandatory now? This should be specified in the RFC I > think. > > If it's about to allow void where it wasn't allowed, I'm personally not > convinced it's a good idea to open one more code-style war on this topic. > When there is only one way to declare something, there is no need to come > to any agreement about the code style. That's a win. > Hello Nicolas No, *nothing* is gonna be mandatory. As per the RFC: > This RFC proposes to introduce the following signatures checks when magic methods are typed: These checks are only gonna be performed when you type your signatures and *only when you type*. So, your example: `__call($name, $arguments)` will work just fine, same as if you don't type `__clone` with `: void`. Is there a better way to phrase that in the RFC? > > > Foo::__isset(string $name): bool; > > Foo::__unset(string $name): void; > > Same comment about LSP, but also about the type: isn't it allowed to have > integers as keys? How does this play with strict_type and array access? > Thanks for raise this. Nowadays, you can't: https://3v4l.org/pPJDt. But, if you call as a method, yes: https://3v4l.org/0VmYQ. So this should be documented in the RFC as a BC Break. > > > /** @param mixed $value */ > > Foo::__set(string $name, $value): void; > > > Is the return now going to be mandatory? > No, as explained above. > And the BIG question: is all this worth the BC break? > My main motivation is to make sure that developers are using the magic methods with the correct type, nothing else. If everyone then agrees that not having these checks is better for the language, no problem on closing this RFC :) Let me know your thoughts. Thanks, > Thanks, > > Nicolas >