Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92343 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74321 invoked from network); 15 Apr 2016 17:12:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Apr 2016 17:12:07 -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.99 as permitted sender) X-PHP-List-Original-Sender: fsb@thefsb.org X-Host-Fingerprint: 173.203.187.99 smtp99.iad3a.emailsrvr.com Linux 2.6 Received: from [173.203.187.99] ([173.203.187.99:51362] helo=smtp99.iad3a.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/77-29891-6E021175 for ; Fri, 15 Apr 2016 13:12:07 -0400 Received: from smtp29.relay.iad3a.emailsrvr.com (localhost.localdomain [127.0.0.1]) by smtp29.relay.iad3a.emailsrvr.com (SMTP Server) with ESMTP id 11D1538016F; Fri, 15 Apr 2016 13:12:03 -0400 (EDT) X-Auth-ID: fsb@thefsb.org Received: by smtp29.relay.iad3a.emailsrvr.com (Authenticated sender: fsb-AT-thefsb.org) with ESMTPSA id E4FE13800CF; Fri, 15 Apr 2016 13:12:02 -0400 (EDT) X-Sender-Id: fsb@thefsb.org Received: from yossy.local (c-66-30-62-12.hsd1.ma.comcast.net [66.30.62.12]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA) by 0.0.0.0:587 (trex/5.5.4); Fri, 15 Apr 2016 13:12:03 -0400 To: Levi Morrison , Larry Garfield References: <57103A46.6040803@garfieldtech.com> Cc: internals Message-ID: <571120E2.8030507@thefsb.org> Date: Fri, 15 Apr 2016 13:12:02 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Nullable Return Type Declaration From: fsb@thefsb.org (Tom Worster) On 4/15/16 12:22 AM, Levi Morrison wrote: > My point is that `foo(bar(), $val)` won't die because bar may return > null. Bar is expected to return null sometimes. > > For example, let's consider an administrator page where they look up > user information based on an identifier. The routine we'll use will > have this signature: > > function get_user(string $id): User | Null; > > It is possible for an identifier to not exist and this is not an error > (database successfully returned no results). If there is no User data > to display then it makes sense for the UI to present that differently. > Thus it makes sense to pass that User | Null onto the code that will > present it: > > $user_data = get_user($id); > // ... > $user_html = render_user_data($user_data); > > In fact this is a common operation that is encountered in many code > bases (I think every single one I've ever looked at). This is a good example. My opinion is that *because* get_user() can return null (a red flag) I prefer to see explicit handing of the null case before doing anything else. If I would end up with `render_user_data(get_user($id))` I would consider it fair to not hint the param because I didn't earn it. I invented the faux docblock tag @sorry for this kind of thing. Tom