Re: [RFC] [DISCUSSION] Ensure correct magic methods' signatures when typed
| From: | Claude Pache | Date: | Tue, 14 Apr 2020 17:45:16 +0000 |
| Subject: | Re: [RFC] [DISCUSSION] Ensure correct magic methods' signatures when typed | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109641@lists.php.net to get a copy of this message | ||
> Le 14 avr. 2020 à 18:53, Nikita Popov <nikita.ppv@gmail.com> a écrit :
>
> On Tue, Apr 14, 2020 at 6:07 PM Claude Pache <claude.pache@gmail.com
> <mailto:claude.pache@gmail.com>> wrote:
>
>
> > Le 14 avr. 2020 à 16:54, Nicolas Grekas <nicolas.grekas+php@gmail.com
> > <mailto:nicolas.grekas%2Bphp@gmail.com>> a écrit :
> >
> > I'm just not sold on allowing "void" on __construct, because the very
> > concept of a return type on a constructor is ... void, and also because of the code style choices
> > this will open (and the CS "wars" I mentioned).
> >
>
> This issue is not specific to magic method like __construct(). It is the whole concept of
> “void” as return type which is, say, “problematic”.
>
> In fact, “void” is not really a return type. It is a way to state that the method is not
> supposed to return anything, which means, as you said very well, that “the very concept of return
> type on [this method] is void”.
>
> That might be a reason to reject the concept of “void” as return type. Or to revive
> https://wiki.php.net/rfc/allow-void-variance
> <https://wiki.php.net/rfc/allow-void-variance>
> <https://wiki.php.net/rfc/allow-void-variance
> <https://wiki.php.net/rfc/allow-void-variance>> . But
> again, the issue is orthogonal to the fact that this particular method is magic, and we should not
> cherry-pick and reject the concept of “void” for __construct() and similar magic methods only.
>
> Constructors not having a return type is standard behavior across most (all?) languages. You
> can't specify a constructor return type in C++. You can't specify one in C#. You
> can't specify one in Java. Off-hand, I can't name a language that both has a first-class
> constructor concept (Rust's "new" idiom does not count) and specifies a return type
> on it.
>
> It would naturally follow that, yes, you can't specify a constructor return type in PHP
> either, just like we enforce right now. Unless we have some strong reason to deviate from standard
> behavior that I do not see?
>
> Regards,
> Nikita
Do those languages allow to return something from the constructor (as does PHP currently)? because
I’m more interested in the semantics of
: void than the exact way to have it.
—Claude