Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79543 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71955 invoked from network); 10 Dec 2014 19:58:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2014 19:58:30 -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:55772] helo=imap2-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/88-29826-5E5A8845 for ; Wed, 10 Dec 2014 14:58:30 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 356338C008D; Wed, 10 Dec 2014 14:47:13 -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 7w9HU2hpaBJK; Wed, 10 Dec 2014 14:47:11 -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 900868C0423; Wed, 10 Dec 2014 14:20:54 -0500 (EST) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: <583B9A4B-68FD-4FB1-B043-0D86E2480EAD@fb.com> Date: Wed, 10 Dec 2014 19:20:52 +0000 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <324758A2-E3A6-46C1-9209-998F7E936B77@ajf.me> References: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> <9230CB24-22FC-4A0E-A9D5-F02523B65A02@ajf.me> <583B9A4B-68FD-4FB1-B043-0D86E2480EAD@fb.com> To: Josh Watzman X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [RFC] Nullsafe calls From: ajf@ajf.me (Andrea Faulds) Hi again. > On 10 Dec 2014, at 19:11, Josh Watzman wrote: >=20 > On Dec 10, 2014, at 9:19 AM, Andrea Faulds wrote: >=20 >> First, how is this substantially different from catching an = exception? With Nikita=92s Exceptions in the Engine RFC, something like = this would be possible: >>=20 >> try { >> return $foo->bar()->qux()->elePHPant()->dance(); >> } catch (EngineException $e) { >> return NULL; >> } >>=20 >> That would essentially do the same as what you=92re proposing: >>=20 >> return $foo?->bar()?->qux()?->elePHPant()?->dance(); >>=20 >> Are there many instances where there=92d be a substantial benefit to = using ?-> versus catching an exception? >=20 > It's an API decision up to the implementors of the object. If you like = using exceptions for *every* failure, then go for it, this syntax won't = cost you anything or get in your way :) >=20 > However, for a lot of failures, I don't feel that exceptions are = appropriate. I tend to only use them for exceptional behavior -- = usually, some failure that needs to be propagated up a few levels up the = stack, to an appropriate error boundary. This doesn't necessarily mean a = completely unrecoverable error, but it's *locally* unrecoverable. For = things that are completely recoverable, returning null might be more = appropriate and more lightweight, and then this nullsafe operator would = be useful at that point. =85huh? I=92m not talking about exceptions the object itself throws. In = PHP 7, if Nikita=92s RFC passes, trying to call a method on NULL will = throw an exception. That largely negates the need for a special = operator, since you can just catch the exception. Thanks. -- Andrea Faulds http://ajf.me/