Re: [RFC] Void Return Type
| From: | Andrea Faulds | Date: | Sat, 14 Feb 2015 12:33:23 +0000 |
| Subject: | Re: [RFC] Void Return Type | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-82682@lists.php.net to get a copy of this message | ||
Hi,
> On 14 Feb 2015, at 05:03, Xinchen Hui <laruence@php.net> wrote:
>
> Hey:
> be honest, I think it's only part of the idea is implemented.
>
> which make it useless.
>
> in PHP, even if you don't return anything, NULL is returned implicitly.
>
> even if a function is declared return nothing(void).
>
> like:
>
> function a() : void {};
>
> following codes still works:
>
> $b = a();
>
> so, if you want a void return type, and if you want it to be a useful feature..
>
> above expr should be invalid with an error " a() return nothing"
I'm not sure about this. PHP has always made functions valid rvalues, for better or for worse.
This RFC could make void functions "truly" void, but that would be a massive change to
support value-less function returns. It would also break existing code which assumes all functions
return a value, which isn't good.
I think this RFC is enough: it would let you enforce that a function doesn't return anything
and makes code more self-documenting. It doesn't affect anything trying to use the
function's implicit return value of NULL, but IDEs and code linters would surely pick up on it
for you. It's still useful even if it doesn't bind the caller.
Thanks.