Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89350 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18626 invoked from network); 23 Nov 2015 20:52:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2015 20:52:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wm0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:35632] helo=mail-wm0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/5B-47837-F8C73565 for ; Mon, 23 Nov 2015 15:52:31 -0500 Received: by wmuu63 with SMTP id u63so70923067wmu.0 for ; Mon, 23 Nov 2015 12:52:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=h/RSo9fl0n63BmVSMTIhHRVcht/IVDCrO8DI/oAu3jU=; b=l0Cz3vzwKB9/RWfbpBibg6xUFbiE+6H1/1R6aVhs5TCyW4BUzIghAab/ZkZWokV2fV XoPAziMc7rOAYfE07a5f8sx5iu8metTrNG8L+6v1HSOjYOlnkBa2YTZ0+ysQG6p99KNf up2iXUUn7cpaKD6Jt9DbyxDPzvlO7A9DVP52sk3Z2qw4WRZs70L5z2qgSNEYsiYiYiE0 hB34DVupP595sDUGu5HGltAPaP1/ZrIKxcsRzbpdOq66ntgwqdoHcIG1P7yYYQcqTNrm 941pT9Ff76/7tUGsyvB39txO2zBbeN8wlaKgxbmJF8IbtirD6F5oiP6FrcUP6BqZJpiw s3Cw== MIME-Version: 1.0 X-Received: by 10.28.125.73 with SMTP id y70mr22144007wmc.95.1448311948527; Mon, 23 Nov 2015 12:52:28 -0800 (PST) Received: by 10.28.98.87 with HTTP; Mon, 23 Nov 2015 12:52:28 -0800 (PST) In-Reply-To: <7641479E-65DD-4B5F-B1E5-2A0D4E91D69B@gmail.com> References: <4D5D4A6D-1E94-4893-B1DF-7A8C616C871A@gmail.com> <20.F5.23339.A9822565@pb1.pair.com> <457D19DF-746D-40D0-BA0F-7064D265901E@gmail.com> <7641479E-65DD-4B5F-B1E5-2A0D4E91D69B@gmail.com> Date: Mon, 23 Nov 2015 13:52:28 -0700 Message-ID: To: shadda Cc: Phil Sturgeon , PHP internals Content-Type: multipart/alternative; boundary=001a1141ea76374ce705253b6792 Subject: Re: [PHP-DEV] PHP7 Coalesce operator From: derokorian@gmail.com (Ryan Pallas) --001a1141ea76374ce705253b6792 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Well use null coalesce + elvis together then? // Coalesce possible null values, and use truthy comparison in elvis to "coalesce" to a default $var =3D ($_GET['possible_value'] ?? $_COOKIE['secondary'] ?? false) ?: DEFAULTS['var']; On Mon, Nov 23, 2015 at 1:16 PM, shadda wrote: > It=E2=80=99s not hate, I happen to like that ?? was added. I=E2=80=99m no= t raising a > concern nor asking for a change in its behavior. Rather, I=E2=80=99m aski= ng for > another, similar operator that=E2=80=99s based on truth-evaluation (with = PHP=E2=80=99s > tender, loving conversion rules baked in), in *addition* to ?? which test= s > for null/undefined exclusively. > > > > On Nov 23, 2015, at 12:08 PM, Phil Sturgeon > wrote: > > > > On Mon, Nov 23, 2015 at 9:52 AM, shadda wrote: > >> Er, that should read, =E2=80=9Canything non (null, false, undefined) i= s true=E2=80=9D > >> > >>> On Nov 23, 2015, at 11:51 AM, shadda wrote: > >>> > >>> Hey, thanks for responding. > >>> > >>> However, I still think that misses the point, or at least the true > utility of what I=E2=80=99m proposing. > >>> > >>> In practice, you can ignore E_NOTICE and php will happily treat null > and !isset() as the same thing in *most* cases, so that=E2=80=99s not a g= ood > indicator of truthiness. > >>> > >>> Basically in ECMA, anything non-null, false, or undefined is true. PH= P > is very similar in that regard, but our reliance on E_NOTICE to (ahem) > enforce isset() checks is why, I assume, we=E2=80=99re introducing the ??= operator > to begin with. > >>> > >>> I just think it=E2=80=99d be nice to have a small variation on this f= eature > that was less concerned with a (defined|null) semantic and more in keepin= g > with PHP=E2=80=99s overall handling of implicit type conversion in expres= sions. > >>> > >>> Does that make more sense? > >>> > >>>> On Nov 22, 2015, at 12:41 PM, Andrea Faulds wrote: > >>>> > >>>> Hi, > >>>> > >>>> shadda wrote: > >>>>> I had a question-suggestion based around the cool new operator we= =E2=80=99re > getting in PHP7, the ?? operator, which as I understand it is the > functional equivalent to perl=E2=80=99s // operator; in that they both te= st for > whether or not a variable is defined, rather than it=E2=80=99s truthiness= . > >>>> > >>>> This is not strictly correct. Though something of a misnomer, the > 'null coalesce operator' checks if a variable doesn't exist, but also tha= t > it is not null, i.e. it functions like isset(). > >>>> > >>>> Thanks. > >>>> > >>>> -- > >>>> Andrea Faulds > >>>> http://ajf.me/ > >>>> > >>>> -- > >>>> PHP Internals - PHP Runtime Development Mailing List > >>>> To unsubscribe, visit: http://www.php.net/unsub.php > >>>> > >>> > >> > >> > >> -- > >> PHP Internals - PHP Runtime Development Mailing List > >> To unsubscribe, visit: http://www.php.net/unsub.php > >> > > > > Ignoring E_NOTICE is generally considered bad practice by many, and > > turning them off just to use ternaries instead of null coalesce (a > > feature we already have) doesn't seem like a benefit. > > > > The ?? is used the same as "a =3D b || c" in Ruby or JS. Doing that in > > PHP wouldn't work well as || works a bit differently, so ?? is used > > instead, just like C and Swift. > > > > Basically... it's all good. And even if you hate it you're months too > > late to raise a concern. :) > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a1141ea76374ce705253b6792--