Re: [RFC] Void Return Type (v0.2, reöp ening)
| From: | Andrea Faulds | Date: | Thu, 15 Oct 2015 15:32:16 +0000 |
| Subject: | Re: [RFC] Void Return Type (v0.2, reöp ening) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88816@lists.php.net to get a copy of this message | ||
Hi Rowan,
Rowan Collins wrote:
I can see the point in denying the right to say "return some_function_expected_to_return_null();" But in a sense this is no different from declaring that a function returns int, and then writing "return some_function_expected_to_return_int();" If a void function can be used in an expression, it can be used in a return expression, and if so, it feels natural for the type hint to propagate: function foo(): void { do_something(); } function wrapped_foo(): void { do_something_else(); return foo(); } // ERROR: can't specify return value in a void function "return foo()" is not illegal because foo is declared void, but because wrapped_foo is - even though the result is exactly as expected.Hmm, this is an interesting case you've pointed out. Being able to do
return some_other_void_function(); is something I've desired in other languages.
But what if that void function you're calling later adds a return value? Now the calling function is returning a value other than null, violating its type hint and producing a runtime error.
It's a shame there's no "tail call this other function and discard its result" construct.
Thanks.
--
Andrea Faulds
http://ajf.me/