Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88842 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76213 invoked from network); 15 Oct 2015 21:05:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Oct 2015 21:05:11 -0000 X-Host-Fingerprint: 2.123.167.169 unknown Received: from [2.123.167.169] ([2.123.167.169:13260] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/10-09496-60510265 for ; Thu, 15 Oct 2015 17:05:11 -0400 Message-ID: <7F.10.09496.60510265@pb1.pair.com> To: internals@lists.php.net References: <0A.C2.33697.6AECE165@pb1.pair.com> X-Mozilla-News-Host: news://news.php.net Date: Thu, 15 Oct 2015 22:05:08 +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: Content-Type: text/plain; charset=UTF-8; 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) Hey Chris, Chris Riley wrote: > Semantically, I don't believe that there is sufficient difference between > "returns no value" and "returns a value which has been defined as having no > value" for us to care about it. The main difference you get between return > type of null and a return type of void seems to be some extra fatal errors, > for a developer there seems little value. > > From a user confusion point of view; PHP currently considers return; and > return null; to be equivalent (in fact some code style checkers will > replace one with the other) If (and only if) a function has a return type > of void these two statements are no longer equivalent - one is a fatal > error one is not. For any other return type specification, return null; and > return; would behave the same. This in itself would be enough for me to be > against adding a return type of void. This is true, but `void` isn't an ordinary return type. It exists to ensure a function doesn't return anything, unlike other return types which exist to ensure a function returns a specific thing. `return null;` is *technically* equivalent to `return;`, but it's not quite the same in intent, usually. We could special-case it and allow it, but why? The return value isn't supposed to be used, why should we allow you to specify it? A void function in PHP does technically produce a result of null, but it might as well be false or -1 or whatever for all we care. Also, if `return null;` is to work, should `return(null);` also work? How about `return \null;`? `return SOME_NULL_CONSTANT;`? It seems silly to me since, again, the return value is insigificant. Thanks. -- Andrea Faulds http://ajf.me/