Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79547 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79293 invoked from network); 10 Dec 2014 20:30:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2014 20:30:11 -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:38949] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id ED/F9-29826-15DA8845 for ; Wed, 10 Dec 2014 15:30:10 -0500 Received: (qmail 5033 invoked from network); 10 Dec 2014 21:30:05 +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:30:05 +0100 To: "'Josh Watzman'" Cc: "'PHP internals'" References: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> <000b01d01494$bb1c6520$31552f60$@tutteli.ch> In-Reply-To: Date: Wed, 10 Dec 2014 21:30:04 +0100 Message-ID: <002801d014b8$151ec360$3f5c4a20$@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+ETsclgEczmegAZpxC2WaSTAy8A== Content-Language: de-ch Subject: AW: [PHP-DEV] [RFC] Nullsafe calls From: php@tutteli.ch ("Robert Stoll") > -----Urspr=FCngliche Nachricht----- > Von: Josh Watzman [mailto:jwatzman@fb.com] > Gesendet: Mittwoch, 10. Dezember 2014 19:43 > An: Robert Stoll > Cc: PHP internals > Betreff: Re: [PHP-DEV] [RFC] Nullsafe calls >=20 > On Dec 10, 2014, at 8:17 AM, Robert Stoll wrote: >=20 > > First of all, I like the RFC, I think as well that it is a useful > > feature for PHP and I already have it on my wish list > > ;) > > > > Yet, either I misunderstand the section about short circuiting or I = propose to change the behaviour. > > > > "If $obj is null, when $obj?->foo(..) executes, the arguments will = still be evaluated." > > > > IMO that is wrong. It should not evaluate the arguments since the = nullsafe operator (sometimes called "safe navigation" > > operator in other languages - which is the better wording IMO, maybe > > change it? But that is just a detail) is just syntactic sugar for = making the call only if $bj is not null. So the following: > > > > [...] > > >=20 > Take a look at the "short circuit" section where I specifically = address this. It was done to make it easier to reason about in a > side-effect-ful language like PHP. With this behavior, when you see >=20 > $x?->f(g(), h()) >=20 > you don't have to worry about thinking whether g() and h() will = actually be evaluated or not -- only the call to f() itself, > which is explicitly marked as nullsafe (i.e., might not happen). It = also comes down to what you mean by "not making the > method call when $x is null" -- we in fact don't make the method call, = but we still prepare everything as if we were going to, > and just decide not to do it at the last moment. >=20 > I feel pretty strongly that this is the correct behavior. It may sound = strange when talking about isolated examples like this, > but in the real-world code I've seen, it is the least confusing. (I'll = see if I can dig up a better example instead of just citing > nebulous "real-world code" ;)) >=20 > Josh >=20 >=20 > -- > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, = visit: http://www.php.net/unsub.php I stick with it, evaluating it does not make sense IMO. If I want to = execute it in any case then I would do something like this currently $g =3D g(); $h =3D h(); if($x !=3D=3D null){ $x->foo($g, $h)->bar(baz()); } And with the ?-> operator: $g =3D g(); $h =3D h(); $x?->foo($g, $h)?->bar(baz()); Where I do not expect that baz() is called. You wrote it will be = confusing for the user if the arguments would not be evaluated. I do not think so, telling them it is a short form for ($x = !=3D=3D null ? $x->foo() : null) is very easy and straight forward for the user to pick up. Therefore, please dig up a = better example. Right now, I think it is a good idea in general to add a nullsafe operator to PHP but not only in the = way mentioned.