Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51836 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27928 invoked from network); 8 Apr 2011 09:07:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Apr 2011 09:07:00 -0000 Authentication-Results: pb1.pair.com header.from=M.Ford@leedsmet.ac.uk; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=M.Ford@leedsmet.ac.uk; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain leedsmet.ac.uk designates 207.126.144.115 as permitted sender) X-PHP-List-Original-Sender: M.Ford@leedsmet.ac.uk X-Host-Fingerprint: 207.126.144.115 eu1sys200aog103.obsmtp.com Linux 2.5 (sometimes 2.4) (4) Received: from [207.126.144.115] ([207.126.144.115:58457] helo=eu1sys200aog103.obsmtp.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 36/31-17421-030DE9D4 for ; Fri, 08 Apr 2011 05:06:58 -0400 Received: from mrelay-c.lmu.ac.uk ([160.9.192.20]) by eu1sys200aob103.postini.com ([207.126.147.11]) with SMTP ID DSNKTZ7QLg2oCYcSrW4ToqtVsmkmXIObHwT7@postini.com; Fri, 08 Apr 2011 09:06:57 UTC Received: from exc-hcas03.leedsmet.ac.uk ([160.9.47.13]) by mrelay-c.lmu.ac.uk with esmtp (Exim 4.60) (envelope-from ) id 1Q87eX-0005wn-6q; Fri, 08 Apr 2011 10:06:53 +0100 Received: from EXC-MBX02.leedsmet.ac.uk ([fe80::a1c1:32b9:3881:d170]) by EXC-HCAS03.leedsmet.ac.uk ([fe80::594c:9dfc:fcca:8c94%11]) with mapi id 14.01.0270.001; Fri, 8 Apr 2011 10:06:53 +0100 To: Adam Richardson , PHP Development Thread-Topic: [PHP-DEV] Implicit isset/isempty check on short-ternary operator Thread-Index: AQHL78FJvUhk/oQtEEqxIF/Taq47RZRH+pgAgAq4wICAAAMYgIAASU0u///vVACAABB/gIAAZEMAgAAhpYCAADAC8A== Date: Fri, 8 Apr 2011 09:06:52 +0000 Message-ID: <3158105795AAC1408619EC8BA03384A90617D5@EXC-MBX02.leedsmet.ac.uk> 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> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.8.18.196] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: M.Ford@leedsmet.ac.uk ("Ford, Mike") > -----Original Message----- > From: Adam Richardson [mailto:simpleshot@gmail.com] > Sent: 08 April 2011 08:02 >=20 > Indeed. >=20 > The '?' character already is special, so using '??' seems like a > safe, > practical approach. However, I'd prefer maintaining the form of the > standard > 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. >=20 > // standard > $value =3D isset($a[$key]) ? $a[$key] : 'Not set'; >=20 > // new ?? double ternary that performs isset check and omits second > expression > $value =3D $a[$key] ?? : 'Not set'; >=20 > // new ?? double ternary that performs isset check and uses second > expression > $value =3D $a[$key] ?? strtoupper($a[$key]) : 'Not set'; >=20 Like it! I would have proposed ??: for the isset() variant of ?:, and I think decomposing it into a full ternary operator in this way, with ??: as a degenerate variant, is brilliant. (Only downside is, people would have to stop referring to *the* ternary operator!) Cheers! Mike --=20 Mike Ford, Electronic Information Developer, Libraries and Learning Innovation,=20=20 Leeds Metropolitan University, C507 City Campus,=20 Woodhouse Lane, LEEDS,=A0 LS1 3HE,=A0 United Kingdom=20 Email: m.ford@leedsmet.ac.uk=20 Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http:= //disclaimer.leedsmet.ac.uk/email.htm