Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92342 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72521 invoked from network); 15 Apr 2016 16:59:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Apr 2016 16:59:42 -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.83 as permitted sender) X-PHP-List-Original-Sender: fsb@thefsb.org X-Host-Fingerprint: 173.203.187.83 smtp83.iad3a.emailsrvr.com Linux 2.6 Received: from [173.203.187.83] ([173.203.187.83:46530] helo=smtp83.iad3a.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BC/17-29891-DFD11175 for ; Fri, 15 Apr 2016 12:59:42 -0400 Received: from smtp19.relay.iad3a.emailsrvr.com (localhost.localdomain [127.0.0.1]) by smtp19.relay.iad3a.emailsrvr.com (SMTP Server) with ESMTP id A61CB18021F; Fri, 15 Apr 2016 12:59:39 -0400 (EDT) X-Auth-ID: fsb@thefsb.org Received: by smtp19.relay.iad3a.emailsrvr.com (Authenticated sender: fsb-AT-thefsb.org) with ESMTPSA id 8C32818032E; Fri, 15 Apr 2016 12:59:39 -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 12:59:39 -0400 To: Larry Garfield , internals@lists.php.net References: <57103A46.6040803@garfieldtech.com> Message-ID: <57111DFA.6090006@thefsb.org> Date: Fri, 15 Apr 2016 12:59:38 -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: <57103A46.6040803@garfieldtech.com> 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/14/16 8:48 PM, Larry Garfield wrote: > I am highly, highly sceptical about nullable parameters or returns, and > frankly would rather they were not included in the language. By nature > they undermine type safety. At best, they indicate to all callers > "*every* time you call this function, you MUST put is_null() around it > or your program may fail randomly." Yes. > While that's better to know > explicitly than not (which is the case for any untyped return, aka any > PHP code pre-7.0), it would be better still to, well, not have to worry > about that billion dollar mistake[1] cropping up in my code. I agree. To be clear, I do not intend the RFC to encourage nullable return or suggest that it's a fine thing to use. But given where we are, it's hard to imagine how to extirpate it. When we started using PHP 7.0 type, initially when authoring new models (and using Yii2), it immediately became clear that we lacked two things: this and void returns. We're getting the latter in 7.1. It would be very nice if we could have both. I'm a practical PHP user, with a generally conservative attitude to the language, often unmoved by proposals add a feature because some other more fashionable language has it (I call it language envy, to borrow from Freud). And while PHP 7.0 is good, I'd rather have Something|null in the return declaration than just in the docblock. That's all. > In a sense, if we really must allow for value-or-null (which I consider > a code smell in the 98% case) I'd prefer if it was ONLY available via > union types: That is, Something|null. That's longer and clumsier to > type, and harder to read. Which it should be. (Static casts in C++ have > a fugly syntax, which has been defended by the language designers on the > grounds that static casts are fugly, so the syntax for them should be as > well to remind you to stop doing it. There is a fair amount of validity > to that argument on affordance grounds, at least within C++.) Using an > easy short hand notation for something that is inherently a code smell > when you're already typing your code only serves to encourage something > we should be training people out of in the first place. With regard to syntax, I prefer the long form `Something|null`. That seems very clear to me. The proposed short-hand ? syntax always makes me think of what I hate most about regex. Tom