Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88816 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23227 invoked from network); 15 Oct 2015 15:32:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Oct 2015 15:32:18 -0000 X-Host-Fingerprint: 2.123.167.169 unknown Received: from [2.123.167.169] ([2.123.167.169:24738] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B0/D4-23021-207CF165 for ; Thu, 15 Oct 2015 11:32:18 -0400 Message-ID: To: internals@lists.php.net References: <0A.C2.33697.6AECE165@pb1.pair.com> <561F7D17.5050306@gmail.com> X-Mozilla-News-Host: news://news.php.net Date: Thu, 15 Oct 2015 16:32:16 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:41.0) Gecko/20100101 Firefox/41.0 SeaMonkey/2.38 MIME-Version: 1.0 In-Reply-To: <561F7D17.5050306@gmail.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 2.123.167.169 Subject: =?UTF-8?Q?Re:_[PHP-DEV]_[RFC]_Void_Return_Type_=28v0.2=2c_re=c3=b6p?= =?UTF-8?Q?ening=29?= From: ajf@ajf.me (Andrea Faulds) 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/