On Tue, 16 Jun 2020 at 13:59, Dan Ackroyd <dan...@basereality.com> wrote:

> To be clear, I'm not sure if I am in favour or against the RFC. The
> real problem is that constructors just don't fit into how we think
> about normal functions is PHP, because of the magic that goes on
> around them and so both void and null as return types would be a
> little bit incorrect.
>


I'm not clear what you mean by this. The definition of ": void"  is
currently that the function must either use "return;" without a value, or
conclude without an explicit "return"; a correctly written constructor
would meet that constraint.

The language doesn't currently prevent void functions from being used in
expression context, but even if it did, that would be consistent with how
constructors are actually called internally, which is roughly equivalent to
this:

$newInstance = initialise_object($classDefinition);
$newInstance->__construct(...$args);
return $newInstance;

If a constructor returns a value, it is simply discarded, so a signature of
void would be completely appropriate.

Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to