Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79534 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54135 invoked from network); 10 Dec 2014 18:43:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2014 18:43:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=jwatzman@fb.com; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jwatzman@fb.com; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain fb.com does not designate 67.231.145.42 as permitted sender) X-PHP-List-Original-Sender: jwatzman@fb.com X-Host-Fingerprint: 67.231.145.42 mx0a-00082601.pphosted.com Linux 2.5 (sometimes 2.4) (4) Received: from [67.231.145.42] ([67.231.145.42:39207] helo=mx0a-00082601.pphosted.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0C/B4-29826-94498845 for ; Wed, 10 Dec 2014 13:43:21 -0500 Received: from pps.filterd (m0044008 [127.0.0.1]) by mx0a-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id sBAIaGjG010840 for ; Wed, 10 Dec 2014 10:43:18 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=facebook; bh=aZ3MtwUieRJ3/p/aRsFFMFD1fnUkzqRJTEeF41fQ/Yw=; b=UMiz9DUXmCi0530cO2/TjnfS5dKKBrHb1M21lqEK1uvCnacNCR1NPedZ+aYUEOnPNYb1 mUCyn/Jr6lwaxgT68jZkvetGPkjIX5iBlCARekIR3h+Y9S83s8BwydQ0J+yNOn9qFAJa zJg/IHbmd39UhOmBHm5ZKtjSsrfY9mXcmfQ= Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-00082601.pphosted.com with ESMTP id 1r6hjcs7q6-1 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 10 Dec 2014 10:43:18 -0800 Received: from m0044008 (m0044008 [127.0.0.1]) by pps.reinject (8.14.5/8.14.5) with SMTP id sBAIhIm1018815 for ; Wed, 10 Dec 2014 10:43:18 -0800 Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 1r6hjcs7q4-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Wed, 10 Dec 2014 10:43:17 -0800 Received: from PRN-MBX02-2.TheFacebook.com ([169.254.5.125]) by PRN-CHUB02.TheFacebook.com ([fe80::5de8:34:5a87:6990%12]) with mapi id 14.03.0195.001; Wed, 10 Dec 2014 10:43:16 -0800 To: Robert Stoll CC: PHP internals Thread-Topic: [PHP-DEV] [RFC] Nullsafe calls Thread-Index: AQHQFATxvp9RjOsogUO8aMy5/EMi+5yJh4YAgAAo4YA= Date: Wed, 10 Dec 2014 18:43:16 +0000 Message-ID: References: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> <000b01d01494$bb1c6520$31552f60$@tutteli.ch> In-Reply-To: <000b01d01494$bb1c6520$31552f60$@tutteli.ch> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.16.4] Content-Type: text/plain; charset="iso-8859-1" Content-ID: <77880336D5D8AB4D94024240DE7E4B10@fb.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.13.68,1.0.33,0.0.0000 definitions=2014-12-10_08:2014-12-10,2014-12-10,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 kscore.is_bulkscore=5.55111512312578e-17 kscore.compositescore=0 circleOfTrustscore=15.112 compositescore=0.994924612563162 urlsuspect_oldscore=0.994924612563162 suspectscore=0 recipient_domain_to_sender_totalscore=0 phishscore=0 bulkscore=0 kscore.is_spamscore=0 recipient_to_sender_totalscore=0 recipient_domain_to_sender_domain_totalscore=1889 rbsscore=0.994924612563162 spamscore=0 recipient_to_sender_domain_totalscore=0 urlsuspectscore=0.9 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1412100177 X-FB-Internal: deliver Subject: Re: [PHP-DEV] [RFC] Nullsafe calls From: jwatzman@fb.com (Josh Watzman) On Dec 10, 2014, at 8:17 AM, Robert Stoll wrote: > 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 > ;) >=20 > Yet, either I misunderstand the section about short circuiting or I propo= se to change the behaviour. >=20 > "If $obj is null, when $obj?->foo(..) executes, the arguments will still = be evaluated." >=20 > IMO that is wrong. It should not evaluate the arguments since the nullsaf= e operator (sometimes called "safe navigation" > operator in other languages - which is the better wording IMO, maybe chan= ge it? But that is just a detail) is just > syntactic sugar for making the call only if $bj is not null. So the follo= wing: >=20 > [...] >=20 Take a look at the "short circuit" section where I specifically address thi= s. It was done to make it easier to reason about in a side-effect-ful langu= age like PHP. With this behavior, when you see $x?->f(g(), h()) 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 marke= d 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 t= he method call, but we still prepare everything as if we were going to, and= just decide not to do it at the last moment. I feel pretty strongly that this is the correct behavior. It may sound stra= nge when talking about isolated examples like this, but in the real-world c= ode I've seen, it is the least confusing. (I'll see if I can dig up a bette= r example instead of just citing nebulous "real-world code" ;)) Josh