Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92694 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23323 invoked from network); 24 Apr 2016 15:18:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Apr 2016 15:18:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=fsb@thefsb.org; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=fsb@thefsb.org; sender-id=pass Received-SPF: pass (pb1.pair.com: domain thefsb.org designates 173.203.187.67 as permitted sender) X-PHP-List-Original-Sender: fsb@thefsb.org X-Host-Fingerprint: 173.203.187.67 smtp67.iad3a.emailsrvr.com Received: from [173.203.187.67] ([173.203.187.67:48588] helo=smtp67.iad3a.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/51-13951-2C3EC175 for ; Sun, 24 Apr 2016 11:18:30 -0400 Received: from smtp1.relay.iad3a.emailsrvr.com (localhost.localdomain [127.0.0.1]) by smtp1.relay.iad3a.emailsrvr.com (SMTP Server) with ESMTP id 4C8A61801E0; Sun, 24 Apr 2016 11:18:24 -0400 (EDT) X-Auth-ID: fsb@thefsb.org Received: by smtp1.relay.iad3a.emailsrvr.com (Authenticated sender: fsb-AT-thefsb.org) with ESMTPSA id 315991800FD; Sun, 24 Apr 2016 11:18:23 -0400 (EDT) X-Sender-Id: fsb@thefsb.org Received: from [10.0.1.2] (c-66-30-62-12.hsd1.ma.comcast.net [66.30.62.12]) (using TLSv1 with cipher DES-CBC3-SHA) by 0.0.0.0:465 (trex/5.5.4); Sun, 24 Apr 2016 11:18:24 -0400 User-Agent: Microsoft-MacOutlook/14.6.2.160219 Date: Sun, 24 Apr 2016 11:18:21 -0400 To: Thomas Bley CC: Message-ID: Thread-Topic: [PHP-DEV] [RFC] Nullable Types References: <570F4BB4.6020709@zend.com> <57112225.6020905@thefsb.org> <57119B5E.6070205@thefsb.org> <20160420165307.9C86E1A83D08@dd1730.kasserver.com> <31.BF.14036.A61D8175@pb1.pair.com> <20160421163334.368CF1A80188@dd1730.kasserver.com> In-Reply-To: <20160421163334.368CF1A80188@dd1730.kasserver.com> Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Nullable Types From: fsb@thefsb.org (Tom Worster) Hi Thomas, Sorry for the delay. I was traveling last week. By convention `return;` in PHP is an early return for a function that returns nothing at all. I think it can be confusing when reading a function to look at a `return;` line and have to remember to look elsewhere to discover what that means. And it can mean something different in every function. I prefer to write functions that return only the declared type. In some cases I need to write functions that return only the declared type or null. That's the limit of what I think PHP 7.1 should provide. Hence, for me this has no attraction but it does introduce new ways to write bugs. So I am not enthusiastic. Tom On 4/21/16, 12:33 PM, "Thomas Bley" wrote: >Hello Tom, > >with default return value I mean to return a certain value if nothing >else is returned (similar to method parameters with a default value). > >example 1: > >declare(strict_types=3D0); > >function my_strpos(string $haystack, string $needle): int =3D false { > return 42; // return 42 > return false; // return false > return true; // return 1 > return; // return false >} > >example 2: > >declare(strict_types=3D1); > >function my_strpos(string $haystack, string $needle): int =3D false { > return 42; // return 42 > return false; // return false > return true; // fatal error > return; // return false >} > >Regards >Thomas > > >fsb@thefsb.org wrote on 21.04.2016 15:05: > >> Hi Thomas, >>=20 >>=20 >> What is a default return declaration? Is this for branches within the >>function >> that do not lead to a return statement? >>=20 >>=20 >> Tom >>=20 >>=20 >>=20 >>=20 >>=20 >> From: Thomas Bley >> Sent: =E2=80=8EWednesday=E2=80=8E, =E2=80=8EApril=E2=80=8E =E2=80=8E20=E2=80=8E, =E2=80=8E2016 =E2=80=8E12=E2=80=8E:=E2=80=8E53=E2=80=8E =E2= =80=8EPM >> To: guilhermeblanco@gmail.com, cornelius.howl@gmail.com, dmitry@zend.com >> Cc: fsb@thefsb.org, internals@lists.php.net >>=20 >>=20 >>=20 >>=20 >>=20 >> What do you think about default return values? >>=20 >> e.g. >>=20 >> function foo(): db_result =3D null { >> } >>=20 >> function canLogin(): bool =3D false { >> } >