Re: [RFC] Void Return Type (v0.2, reöp ening)
| From: | Rowan Collins | Date: | Thu, 15 Oct 2015 16:21:28 +0000 |
| Subject: | Re: [RFC] Void Return Type (v0.2, reöp ening) | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88823@lists.php.net to get a copy of this message | ||
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]