Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79518 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70120 invoked from network); 9 Dec 2014 23:31:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2014 23:31:38 -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:12387] helo=mx0a-00082601.pphosted.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 91/79-09154-85687845 for ; Tue, 09 Dec 2014 18:31:36 -0500 Received: from pps.filterd (m0044010 [127.0.0.1]) by mx0a-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id sB9NUO53016528 for ; Tue, 9 Dec 2014 15:31:33 -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=PHKx7FKwJRgDPbH1l8qsaJP/uJA4MegOJRHyImWp8Go=; b=GmUI74pW7ERobZBZ3YKVOI8WA9PA0Cz1tU++gIRUTvY5+qSxrbNbquEWX0xXq9GCYWCW H73Y/twH5oVrcHfyAMqyjQAYRBbwgFv/n8fFp3GLLcuK2GgLxjMb2EL4aiFZyTTnpj2H HaZulle3xbld5q/BDkKNBwaPfvHXAEq4gtA= Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-00082601.pphosted.com with ESMTP id 1r68yk880p-1 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 09 Dec 2014 15:31:33 -0800 Received: from m0044010 (m0044010 [127.0.0.1]) by pps.reinject (8.14.5/8.14.5) with SMTP id sB9NVWJ0017485 for ; Tue, 9 Dec 2014 15:31:32 -0800 Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 1r68yk880m-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Tue, 09 Dec 2014 15:31:32 -0800 Received: from PRN-MBX02-2.TheFacebook.com ([169.254.5.125]) by PRN-CHUB16.TheFacebook.com ([fe80::7948:a494:45d7:3dd9%12]) with mapi id 14.03.0195.001; Tue, 9 Dec 2014 15:31:31 -0800 To: Andrea Faulds CC: PHP internals Thread-Topic: [PHP-DEV] [RFC] Nullsafe calls Thread-Index: AQHQFATxvp9RjOsogUO8aMy5/EMi+5yIauGAgAADuYA= Date: Tue, 9 Dec 2014 23:31:30 +0000 Message-ID: References: <95A581EE-A062-4926-BE44-BCA87FC9B356@fb.com> <0A19AD11-E5B4-4C4E-A69A-C7D6F2E2244A@ajf.me> In-Reply-To: <0A19AD11-E5B4-4C4E-A69A-C7D6F2E2244A@ajf.me> 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="Windows-1252" Content-ID: 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-09_07:2014-12-09,2014-12-09,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 kscore.is_bulkscore=0 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-1412090229 X-FB-Internal: deliver Subject: Re: [PHP-DEV] [RFC] Nullsafe calls From: jwatzman@fb.com (Josh Watzman) On Dec 9, 2014, at 3:18 PM, Andrea Faulds wrote: >> On 9 Dec 2014, at 23:07, Josh Watzman wrote: >>=20 >> Hey internals! A useful feature that Hack picked up in the last few mont= hs are "nullsafe calls", a way of propagating failure forward in a series o= f 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 t= he RFC itself for a full discussion of the motivation for the feature, as w= ell as the feature itself: >>=20 >> https://urldefense.proofpoint.com/v1/url?u=3Dhttps://wiki.php.net/rfc/nu= llsafe_calls&k=3DZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=3DNOz6YOAf%2F6vcJtVVDrd%= 2F2w%3D%3D%0A&m=3DPWfP%2BxZeAyjdTrP6VD3DSUmxrBjiUYvk0TNF5G5e6Ag%3D%0A&s=3D1= 6ce2443111cdb22b84068fd36e93c14d68190e3fe9a2302cf576464b71d28bd >=20 > Hi! >=20 > In a way, this would complement the ?? null coalescing operator we=92re a= dding. :) >=20 > Two thoughts, though: >=20 > 1) Wouldn=92t it be useful to also have this for properties? If you=92re = going down a long list of property accesses, $foo?->bar?->qux is probably n= icer than if ($foo !=3D=3D NULL && $foo->bar !=3D=3D NULL) { $foo->bar->qux= ; =85 } - on the other hand, the ?? operator partly covers this and even ha= ndles arrays, as you can do $foo->bar[=91elePHPant']->qux[=91boop=92] ?? NU= LL already. We also couldn=92t add something like ?-> for arrays, as the ?[= ] syntax is ambiguous (looks like ternary with short array syntax). Property access could be useful as well, I just didn't want to deal with it= for the first version of the RFC. It's actually already listed in "future = scope". :) If this method call portion goes well, I'd be willing to submit = an RFC/implementation for that as well, but I wanted to get method calls do= ne first. (It's also somewhat less clearly useful than method calls, especi= ally with '??' as you point out, which is why I went with method calls firs= t :)) > 2) It=92d probably be better if you made a language specification patch b= efore, not after, the RFC is accepted. Having to specify the syntax and sem= antics formally can make what the operator does clearer and help to spot is= sues. Plus, going forward, the language specification should not be an afte= rthought. Definitely not an afterthought. I just want to get through all of the "not = clear if it's going to work" bits -- first, the feasibility of the actual i= mplementation, then whether the RFC got good reception on internals. I'll m= ake sure to have a spec diff before the RFC goes up for a vote -- does that= sound good? > Otherwise, though, I=92m in favour of this change. Thanks for the feedback! Josh