Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79517 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67621 invoked from network); 9 Dec 2014 23:18:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2014 23:18:21 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.207 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.207 imap2-2.ox.privateemail.com Received: from [192.64.116.207] ([192.64.116.207:60828] helo=imap2-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/09-09154-B3387845 for ; Tue, 09 Dec 2014 18:18:19 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 77AFC8C0080; Tue, 9 Dec 2014 18:18:16 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap2.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap2.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id CvAn5S0vbZ-e; Tue, 9 Dec 2014 18:18:16 -0500 (EST) Received: from oa-res-26-240.wireless.abdn.ac.uk (oa-res-26-240.wireless.abdn.ac.uk [137.50.26.240]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id AFBBC8C0009; Tue, 9 Dec 2014 18:18:15 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> Date: Tue, 9 Dec 2014 23:18:13 +0000 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <0A19AD11-E5B4-4C4E-A69A-C7D6F2E2244A@ajf.me> References: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> To: Josh Watzman X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [RFC] Nullsafe calls From: ajf@ajf.me (Andrea Faulds) > On 9 Dec 2014, at 23:07, Josh Watzman wrote: >=20 > Hey internals! A useful feature that Hack picked up in the last few = months are "nullsafe calls", a way of propagating failure forward in a = series of chained method calls to the end of the whole computation, = getting rid of a lot of the boilerplate in the middle. I think the = feature would be a good one for PHP as well, so I'm submitting this RFC = to add it -- you can see the RFC itself for a full discussion of the = motivation for the feature, as well as the feature itself: >=20 > https://wiki.php.net/rfc/nullsafe_calls Hi! In a way, this would complement the ?? null coalescing operator we=E2=80=99= re adding. :) Two thoughts, though: 1) Wouldn=E2=80=99t it be useful to also have this for properties? If = you=E2=80=99re going down a long list of property accesses, = $foo?->bar?->qux is probably nicer than if ($foo !=3D=3D NULL && = $foo->bar !=3D=3D NULL) { $foo->bar->qux; =E2=80=A6 } - on the other = hand, the ?? operator partly covers this and even handles arrays, as you = can do $foo->bar[=E2=80=98elePHPant']->qux[=E2=80=98boop=E2=80=99] ?? = NULL already. We also couldn=E2=80=99t add something like ?-> for = arrays, as the ?[] syntax is ambiguous (looks like ternary with short = array syntax). 2) It=E2=80=99d probably be better if you made a language specification = patch before, not after, the RFC is accepted. Having to specify the = syntax and semantics formally can make what the operator does clearer = and help to spot issues. Plus, going forward, the language specification = should not be an afterthought. Otherwise, though, I=E2=80=99m in favour of this change. Thanks! -- Andrea Faulds http://ajf.me/