Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89347 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12723 invoked from network); 23 Nov 2015 20:08:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2015 20:08:15 -0000 Authentication-Results: pb1.pair.com header.from=pjsturgeon@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pjsturgeon@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.46 as permitted sender) X-PHP-List-Original-Sender: pjsturgeon@gmail.com X-Host-Fingerprint: 209.85.215.46 mail-lf0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:34704] helo=mail-lf0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/4A-47837-D2273565 for ; Mon, 23 Nov 2015 15:08:14 -0500 Received: by lffu14 with SMTP id u14so118160163lff.1 for ; Mon, 23 Nov 2015 12:08:10 -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:content-transfer-encoding; bh=KCAFesAzGbsnARPWy/l6ZBAvcij/RrPZwtlUoG3xLsM=; b=Kp7I8LXz2auCjLs+v9F/ew5+4Hh1GO3Iue14hJumcGumU0BzIITCJdCkCHPai1MNv1 fB0eUZUwGLZPGMsnf3c4lIjVVUbk1ql30e/Z1UOZw2rPs9vb3/bxOMKd4Db1KdFJMAeE uc8K59FH531IuV8lGIp2xtw3Z7td1orMe4LYdroVcJ59q9zNxgkPizVXQGWLlm/I4lJd vBXUqQhLSM152ERIxfUuCDYHgwG579mXaYQs4H8zmoSbd9HzkdHgHijn8Cx0VWIef8cO K8gWUEBUuy46o9RcOvD2WpbQhkGw/NLSSTPRIsQDfI8tuOG+lrwkKsi2Re5ZONqU9v94 oQ9g== MIME-Version: 1.0 X-Received: by 10.25.153.144 with SMTP id b138mr9596821lfe.167.1448309290320; Mon, 23 Nov 2015 12:08:10 -0800 (PST) Received: by 10.114.31.141 with HTTP; Mon, 23 Nov 2015 12:08:10 -0800 (PST) In-Reply-To: <457D19DF-746D-40D0-BA0F-7064D265901E@gmail.com> References: <4D5D4A6D-1E94-4893-B1DF-7A8C616C871A@gmail.com> <20.F5.23339.A9822565@pb1.pair.com> <457D19DF-746D-40D0-BA0F-7064D265901E@gmail.com> Date: Mon, 23 Nov 2015 10:08:10 -1000 Message-ID: To: shadda Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] PHP7 Coalesce operator From: pjsturgeon@gmail.com (Phil Sturgeon) On Mon, Nov 23, 2015 at 9:52 AM, shadda wrote: > Er, that should read, =E2=80=9Canything non (null, false, undefined) is t= rue=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 utili= ty 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 i= ndicator of truthiness. >> >> Basically in ECMA, anything non-null, false, or undefined is true. PHP i= s very similar in that regard, but our reliance on E_NOTICE to (ahem) enfor= ce isset() checks is why, I assume, we=E2=80=99re introducing the ?? operat= or to begin with. >> >> I just think it=E2=80=99d be nice to have a small variation on this feat= ure that was less concerned with a (defined|null) semantic and more in keep= ing with PHP=E2=80=99s overall handling of implicit type conversion in expr= essions. >> >> 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=99s truthin= ess. >>> >>> 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. :)