Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89351 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20334 invoked from network); 23 Nov 2015 21:02:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2015 21:02:23 -0000 Authentication-Results: pb1.pair.com header.from=shadda@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=shadda@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.44 as permitted sender) X-PHP-List-Original-Sender: shadda@gmail.com X-Host-Fingerprint: 209.85.220.44 mail-pa0-f44.google.com Received: from [209.85.220.44] ([209.85.220.44:34981] helo=mail-pa0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BA/AB-47837-DDE73565 for ; Mon, 23 Nov 2015 16:02:21 -0500 Received: by pacej9 with SMTP id ej9so202266910pac.2 for ; Mon, 23 Nov 2015 13:02:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=m+gZmucAAOgzpgvpr+OXXnZgvw/d9yOz1p2kdNwVzrQ=; b=luvCsdFinYw6GvNP5w1sV1eANR+Z7yfLTBsNOrqb0v6YEknuBUEv7bW7gkSG8uuJFK ++LtoEl1SSrO4uhTig0t06XLQ5i8Ynwr1hPa2Fjl3CVyBfvbe05i9pHps38s3V1d7HBd l8tWscf2n3qnBRPXQFhWh23n4xQ5Y437AG4BQbLt3wRO4dgpZQtI8kya0mGHLpFmeux0 z+GUN+Q+aHYfazMonAAHZVZWF95kip3J8pUmkvVXERP4VTE7jGOIZdK8qbkZC6advc6m y+oYGmwOdVXhicTWhWjhwOBTZGECLCTcA/jKAqykpVH7NrkRMVVBxCIF7szJkfsi0QXH rzsA== X-Received: by 10.98.19.130 with SMTP id 2mr18437485pft.93.1448312538563; Mon, 23 Nov 2015 13:02:18 -0800 (PST) Received: from [192.168.0.18] (70-36-238-3.dsl.static.fusionbroadband.com. [70.36.238.3]) by smtp.gmail.com with ESMTPSA id b17sm11109277pfj.43.2015.11.23.13.02.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Nov 2015 13:02:17 -0800 (PST) Content-Type: multipart/alternative; boundary="Apple-Mail=_0DF25DF7-865B-471D-B82B-6A1C65DE7ABF" Mime-Version: 1.0 (Mac OS X Mail 9.0 \(3094\)) In-Reply-To: Date: Mon, 23 Nov 2015 13:02:16 -0800 Cc: Phil Sturgeon , PHP internals Message-ID: <13FE7176-D9B2-43D2-89C9-F873EF6BF141@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> To: Ryan Pallas X-Mailer: Apple Mail (2.3094) Subject: Re: [PHP-DEV] PHP7 Coalesce operator From: shadda@gmail.com (shadda) --Apple-Mail=_0DF25DF7-865B-471D-B82B-6A1C65DE7ABF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 That=E2=80=99s not a bad idea, but it=E2=80=99s still limited in certain = cases, where your list of possibles is, lets say, complex.=20 At this point, I think you guys get what I=E2=80=99m after, and I=E2=80=99= m wondering if anyone else finds the idea as useful I as do. In fact, if it didn=E2=80=99t break the One Law of PHP (thou shalt not = break BC), I might even suggest just giving ?: the same super power as = ??, in not throwing a notice.=20 > On Nov 23, 2015, at 12:52 PM, Ryan Pallas = wrote: >=20 > Well use null coalesce + elvis together then? >=20 > // 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']; >=20 > 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 = not raising a concern nor asking for a change in its behavior. Rather, = I=E2=80=99m asking 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 tests for null/undefined = exclusively. >=20 >=20 > > 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) is 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 good indicator of truthiness. > >>> > >>> Basically in ECMA, anything non-null, false, or undefined is true. = PHP 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 feature that was less concerned with a (defined|null) semantic and = more in keeping with PHP=E2=80=99s overall handling of implicit type = conversion in expressions. > >>> > >>> 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 test for whether or not a variable is defined, rather than it=E2=80=99= s truthiness. > >>>> > >>>> This is not strictly correct. Though something of a misnomer, the = 'null coalesce operator' checks if a variable doesn't exist, but also = that 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. :) >=20 >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php = >=20 >=20 --Apple-Mail=_0DF25DF7-865B-471D-B82B-6A1C65DE7ABF--