Pedro Cordeiro wrote on 15/10/2015 17:14:
I've been thinking about what PHP should do when accessing the return value of a `void` function, and so far, I think the consistent thing should be to get NULL, while throwing an E_NOTICE.

$a = $b; //$b wasn't initiated.

This does the same thing. I tried accessing what was supposed to be 'nothing' ($b), and got NULL with an E_NOTICE being thrown.

function myFunc() : void { ... }
$a = myFunc();

I see no reason why this should silently assign NULL to $a, *specially* with "return null;" being explicitly forbidden. ... The behaviour should be consistent (NULL should be accessed, as for all undefined things), with an E_NOTICE.

I don't know how easy this would be to implement, but I agree that this would make the "void" keyword feel more meaningful.

Does the Engine have a way to know whether a return value is being used or discarded for optimisation purposes? If so, could that logic be hooked to provide the Notice?

Regards,
--
Rowan Collins
[IMSoP]

Reply via email to