On Thu, Jun 18, 2020, at 3:49 PM, Andreas Hennings wrote:
> On the other hand, for a constructor the ": void" is just stating the
> obvious.
> Even if you see a constructor without ": void", you still know that this is
> not meant to return anything.
> Either because it is generally agreed to be bad (PHP7) or because it is
> deprecated (PHP8) or because it is illegal (PHP9)
I see this in the same category as __toString().
Adding : string to that method provides exactly zero additional information. You know
it's going to return a string. That's it's whole purpose. On the off chance someone
is returning a non-string right now, they're very clearly Doing It Wrong(tm). However, the
stringable RFC added the ability to put : string on the method in order to be clearer,
more explicit, and to not annoy type fans who are like "Ah, I've typed every one of my
methods... except this one, because I can't, raaaah!"
I see this as the same for constructors. Any constructor returning non-void right now is Doing It
Wrong(tm), and you know that going in. But being able to make the obvious explicit still has its
advantages, both for documentation and for consistency.
I am in favor of this RFC for that reason.
--Larry Garfield