Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51837 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29395 invoked from network); 8 Apr 2011 09:12:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Apr 2011 09:12:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=landeholm@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=landeholm@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: landeholm@gmail.com X-Host-Fingerprint: 209.85.210.170 mail-iy0-f170.google.com Received: from [209.85.210.170] ([209.85.210.170:36217] helo=mail-iy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/81-17421-E61DE9D4 for ; Fri, 08 Apr 2011 05:12:15 -0400 Received: by iyb12 with SMTP id 12so4035589iyb.29 for ; Fri, 08 Apr 2011 02:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=Uk+9lPUCugdJ7oRUJPE3QIPiO+vDCQMwTsxhmS69R7Y=; b=tN/g5cU1oYxtWYYXGgXmYAx80erPyckQlm6g5BxZugHtIFmZhZh+1irwo3xrDK9MhY SNqMslZIauDP3dyqxm7QOoAks9foF0HoR1T1S5WwaeQ0KqPxSAQO6WrPaJWTF80ZEY5o 7UsV4gV2hjpgYdBOldb8taLF8WKqmpf1lt2o8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=YPV+jXwQt5xQmf8g5+hW8ummcNmuONlcavaory8M6uJ6FJMul3GrhYVal8mSP++IWg Y694rxHbWhw3RCgQjA6oxivHKBYPJNR5PSyiad3bc80mneKI57hBE6nm6JOL4gn/3r+7 F5fKqEvr5lsFefA2MlvIT+Y6FsXmfVA1QgTKE= MIME-Version: 1.0 Received: by 10.43.55.83 with SMTP id vx19mr3427931icb.24.1302253931076; Fri, 08 Apr 2011 02:12:11 -0700 (PDT) Received: by 10.231.39.132 with HTTP; Fri, 8 Apr 2011 02:12:10 -0700 (PDT) In-Reply-To: References: <4D950434.3060704@yahoo.com.au> <4D9E0543.1080600@lerdorf.com> <69.82.36433.EC33E9D4@pb1.pair.com> <4D9E34C4.5000406@lerdorf.com> <4D9E429B.20503@sugarcrm.com> <4D9E96B6.6060401@lerdorf.com> Date: Fri, 8 Apr 2011 11:12:10 +0200 Message-ID: To: Adam Richardson , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: landeholm@gmail.com (Hannes Landeholm) Hi. I like Adam's suggestion _a lot_ however I'd also find a third case very useful. In addition to: ********* // standard $value =3D isset($a[$key]) ? $a[$key] : 'Not set'; // new ?? double ternary that performs isset check and omits second expression $value =3D $a[$key] ?? : 'Not set'; // new ?? double ternary that performs isset check and uses second expression $value =3D $a[$key] ?? strtoupper($a[$key]) : 'Not set'; ********* I would also like a case where you could: // new ?? double ternary that performs isset check and uses null $value =3D $a[$key]??; This would replace a lot of ugly code I have where: (the @ operator is ugly= ) $value =3D @$a[$key]; When I want to treat all non existing indexes as containing the null value. ~Hannes On 8 April 2011 09:02, Adam Richardson wrote: > > > > > > >> =A0We need to be careful about changing the beahviour of existing > > operators. > > > > Indeed. > > The '?' character already is special, so using '??' seems like a safe, > practical approach. However, I'd prefer maintaining the form of the stand= ard > ternary operator with the colon ($value =3D $var['bar'] ?? : 'Bar was not > set'; // value =3D"Bar was not) so the '??' operator could be applied in = any > situation that one would normally use the standard ternary operator. > > // standard > $value =3D isset($a[$key]) ? $a[$key] : 'Not set'; > > // new ?? double ternary that performs isset check and omits second > expression > $value =3D $a[$key] ?? : 'Not set'; > > // new ?? double ternary that performs isset check and uses second > expression > $value =3D $a[$key] ?? strtoupper($a[$key]) : 'Not set'; > > Granted, the last example might be infrequent, but I think there's also a > value in keeping the form of the double ternary (if used at all) the same= as > the standard ternary operator for consistency sake. > > Adam > > -- > Nephtali: =A0A simple, flexible, fast, and security-focused PHP framework > http://nephtaliproject.com