Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92323 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3478 invoked from network); 15 Apr 2016 00:33:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Apr 2016 00:33:48 -0000 Authentication-Results: pb1.pair.com header.from=fsb@thefsb.org; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=fsb@thefsb.org; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain thefsb.org designates 173.203.187.75 as permitted sender) X-PHP-List-Original-Sender: fsb@thefsb.org X-Host-Fingerprint: 173.203.187.75 smtp75.iad3a.emailsrvr.com Linux 2.6 Received: from [173.203.187.75] ([173.203.187.75:48248] helo=smtp75.iad3a.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/86-64966-BE630175 for ; Thu, 14 Apr 2016 20:33:48 -0400 Received: from smtp2.relay.iad3a.emailsrvr.com (localhost.localdomain [127.0.0.1]) by smtp2.relay.iad3a.emailsrvr.com (SMTP Server) with ESMTP id 2ACE41804C7; Thu, 14 Apr 2016 20:33:45 -0400 (EDT) X-Auth-ID: fsb@thefsb.org Received: by smtp2.relay.iad3a.emailsrvr.com (Authenticated sender: fsb-AT-thefsb.org) with ESMTPSA id 16D5D18035F; Thu, 14 Apr 2016 20:33:42 -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); Thu, 14 Apr 2016 20:33:45 -0400 User-Agent: Microsoft-MacOutlook/14.6.2.160219 Date: Thu, 14 Apr 2016 20:33:41 -0400 To: Levi Morrison CC: php-internals Message-ID: Thread-Topic: [PHP-DEV] [RFC] Nullable Return Type Declaration References: In-Reply-To: Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Nullable Return Type Declaration From: fsb@thefsb.org (Tom Worster) On 4/14/16, 5:46 PM, "Levi Morrison" wrote: >Having a separate method instead of `foo(null, "value")` makes it >difficult to use for the result of a function. I suspect that might be a good thing:) I don't know for sure but the possibility exists. >Assume `bar()` returns >`Bar | Null`; this would no longer work if they were separated: > > foo(bar(), "value") > >Functions are often composed so if something is the output of one >function it will likely be the input to another. Thus if returning >optionally null values is important to you so should optionally null >parameters. This was a chin-scratcher for me. On one hand, I see what you mean. On the other I couldn't think of an example from my experience (which I admit is very narrow -- I live a sheltered life) of such a bar() that I would feed straight foo(). The semantic convention for Something or null return, as I see it, is when bar() returns null, it is saying "I got nothing". What kind of foo() does the same thing to nothing at all as it does to a Something object? This is where I got stuck. Say I was doing the composition instead via chaining. Something::bar()->foo("value") is nonsense if bar() could return null. This suggests to me that the other composition might not be wise. *Either* bar() should not be returning Something or null (maybe it should instead return some other type that can represent all the possible returns) *or* we shouldn't try to compose like this and should test for the Somethingness of bar()'s return before apply ->foo("value") or foo(=E2=80=A6, "value") to it. Or maybe this API needs an even more fundamental redesign. So, from my perspective, this might be an example of the limitation nudging us to think harder about the design. Tom