Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77103 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36490 invoked from network); 8 Sep 2014 13:58:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Sep 2014 13:58:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:57818] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/D0-31206-206BD045 for ; Mon, 08 Sep 2014 09:58:28 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id DF8A12400C2; Mon, 8 Sep 2014 09:58:23 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id QwZ9Sa4VasyN; Mon, 8 Sep 2014 09:58:23 -0400 (EDT) Received: from oa-res-27-90.wireless.abdn.ac.uk (oa-res-27-90.wireless.abdn.ac.uk [137.50.27.90]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id A90DA2400D7; Mon, 8 Sep 2014 09:58:21 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <540D638B.8010303@php.net> Date: Mon, 8 Sep 2014 14:58:17 +0100 Cc: Sherif Ramadan , Pierre Joye , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <24B60FB5-35B8-4B6F-AD6C-54A8B24D4462@ajf.me> References: <540D638B.8010303@php.net> To: Michael Wallner , Shashank Kumar , Simon Schick X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] Implicit isset() in Shorthand Ternary Operator From: ajf@ajf.me (Andrea Faulds) On 8 Sep 2014, at 09:06, Michael Wallner wrote: > On 07/09/14 14:25, Andrea Faulds wrote: >>=20 >> On 7 Sep 2014, at 13:22, Sherif Ramadan >> wrote: >>=20 >>> I've played around with this branch for a bit and seems reasonable, >>> passes the tests, and doesn't seem to have any serious >>> issues/memories leaks AFAICT. >>=20 >> There=92s actually a quite serious issue just now, which is that it >> evaluates the first operand twice if it=92s not empty. This is = because >> $a ?: $b is expanded to empty($a) ? $b : $a, such that if you did >> something which mutates state in there, it=92d happen twice. This is >> obviously not good, and I=92m going to figure out how to fix this. >>=20 >=20 > This could very well be the reason why it is like it is today. I doubt it, it=92s possible to avoid double-evalution, and I don=92t = think it=92s terribly difficult. I just did things the easy way and it = turns out that has problems. On 8 Sep 2014, at 13:04, Shashank Kumar = wrote: > Rather than giving a new meaning to an old operator why not have a = different operator for this? > .NET has a 'null coalescing' operator for the same purpose which works = out quite well in the given situation=20 > and is non-ambiguous as well. > http://msdn.microsoft.com/en-us/library/ms173224.aspx We could add such an operator, perhaps with the ?? syntax. However, I = don=92t really like the idea. It=92s too similar to ?: so I don=92t = think it=92d be accepted, and even if it was, I=92m not sure we really = need another operator. I=92d much rather just make ?: do what, IMO, is = the right thing and what it always should have done. On 8 Sep 2014, at 08:58, Simon Schick wrote: > I feel more like Sherif Ramadan. Even so I've quite often been in the = same situation, I don't think it's a good solution to change something = like that, just for the shorthand-operator. >=20 > I think, the notice is really valuable when accessing the value and = doing something with it - like myFunction($_GET['not_set']), but if = you're just checking for the existence, I, too, think it is more = annoying. My way was to suppress it by adding the silence-operator ;) >=20 > I always used like: > @$_GET['mykey'] ?: =94=94 The silence operator is bad for three reasons. First, it=92s very slow, = having a significant performance impact. Second, @ silences not only = innocuous E_NOTICEs, but *all* errors, even very serious ones. That=92s = not good. The third is that it interacts with some error handlers badly, = or so I=92ve heard. > I can't come up with a good mid-way right now, but I don't think it's = a good way to change this ONLY for the short-hand operator. Actually, there is a case for doing it for $a ?: $b and not $a ? $a : = $b, in that it could avoid double evaluation (you=92d be able to do = foo()[0] ?: $bar and foo() would only be called once) and because with = the full-length ternary operator, it wouldn=92t really help you much: = $_GET[=91foo=92] ? $_GET[=91foo=92] : =91blah=92 isn=92t much shorter = than the version with explicit isset. -- Andrea Faulds http://ajf.me/