Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92330 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36961 invoked from network); 15 Apr 2016 09:55:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Apr 2016 09:55:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lsces.co.uk from 217.147.176.214 cause and error) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 217.147.176.214 mail4-2.serversure.net Linux 2.6 Received: from [217.147.176.214] ([217.147.176.214:36233] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/31-29891-C7AB0175 for ; Fri, 15 Apr 2016 05:55:09 -0400 Received: (qmail 9203 invoked by uid 89); 15 Apr 2016 09:55:05 -0000 Received: by simscan 1.3.1 ppid: 9192, pid: 9200, t: 0.0780s scanners: attach: 1.3.1 clamav: 0.96/m:52/d:10677 Received: from unknown (HELO ?10.0.0.7?) (lester@rainbowdigitalmedia.org.uk@81.153.92.101) by mail4.serversure.net with ESMTPA; 15 Apr 2016 09:55:05 -0000 To: internals@lists.php.net References: <57103A46.6040803@garfieldtech.com> Message-ID: <5710BA79.5060108@lsces.co.uk> Date: Fri, 15 Apr 2016 10:55:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Nullable Return Type Declaration From: lester@lsces.co.uk (Lester Caine) On 15/04/16 05:22, Levi Morrison wrote: >> Unless you like having is_null() scattered around your code in a hundred >> > places... I don't. :-) You have lots of code instead in exception handling away fro the normal program flow? >> > [1] https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions >> > >> > --Larry Garfield > 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). That is a possible database type scenario, although on all of my systems, the 'guest' user will be accessed as a default which gives the default user data set. The main thing I see with the 'null is not needed' argument is that it instead relies on 'exception handling'? If I am scanning a file or reading a record set, at some point I hit the end, and in ALL my code base I get a null object rather than result object, be that reading and processing a file or a database feed. We have already had the complaints about file handling should give an exception when there is nothing left, but MY workflow keeps everything in line ... when the last record is processed we see the 'null' and progress to the next step in the process. There is nothing here that needs to involve throwing exceptions which may well be coded out of line with the main program flow and make debugging more difficult? -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk