Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79546 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77131 invoked from network); 10 Dec 2014 20:19:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2014 20:19:58 -0000 Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:47543] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 86/99-29826-BEAA8845 for ; Wed, 10 Dec 2014 15:19:56 -0500 Received: (qmail 30112 invoked from network); 10 Dec 2014 21:19:52 +0100 Received: from cm56-129-238.liwest.at (HELO RoLaptop) (86.56.129.238) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 10 Dec 2014 21:19:51 +0100 To: "'Andrea Faulds'" , "'Josh Watzman'" Cc: "'PHP internals'" References: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> <9230CB24-22FC-4A0E-A9D5-F02523B65A02@ajf.me> <583B9A4B-68FD-4FB1-B043-0D86E2480EAD@fb.com> <324758A2-E3A6-46C1-9209-998F7E936B77@ajf.me> In-Reply-To: <324758A2-E3A6-46C1-9209-998F7E936B77@ajf.me> Date: Wed, 10 Dec 2014 21:19:50 +0100 Message-ID: <002701d014b6$a763bfc0$f62b3f40$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQLlQZUb/bhxOgCXUpI56Nr+ETsclgKgkgVsAZ6E7usB2APPTpouL8uw Content-Language: de-ch Subject: AW: [PHP-DEV] [RFC] Nullsafe calls From: php@tutteli.ch ("Robert Stoll") > -----Urspr=FCngliche Nachricht----- > Von: Andrea Faulds [mailto:ajf@ajf.me] > Gesendet: Mittwoch, 10. Dezember 2014 20:21 > An: Josh Watzman > Cc: PHP internals > Betreff: Re: [PHP-DEV] [RFC] Nullsafe calls >=20 > Hi again. >=20 > > On 10 Dec 2014, at 19:11, Josh Watzman wrote: > > > > On Dec 10, 2014, at 9:19 AM, Andrea Faulds wrote: > > > >> First, how is this substantially different from catching an = exception? With Nikita=92s Exceptions in the Engine RFC, > something like this would be possible: > >> > >> try { > >> return $foo->bar()->qux()->elePHPant()->dance(); > >> } catch (EngineException $e) { > >> return NULL; > >> } > >> > >> That would essentially do the same as what you=92re proposing: > >> > >> return $foo?->bar()?->qux()?->elePHPant()?->dance(); > >> > >> Are there many instances where there=92d be a substantial benefit = to using ?-> versus catching an exception? > > > > 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 :) > > > > 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. >=20 > =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. >=20 > Thanks. > -- > Andrea Faulds > http://ajf.me/ > > -- > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, = visit: http://www.php.net/unsub.php I think it is a matter of taste whether you use try/catch as control = structure or only as exception handling. I for myself usually try to avoid using it as control structure and thus would = write something like: if($a !=3D=3D null){ $a->foo(bar()); } And for this case the ?-> operator seems perfect for me - as long as it = does not evaluate bar().=20