Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70421 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80851 invoked from network); 26 Nov 2013 18:00:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2013 18:00:36 -0000 Received: from [127.0.0.1] ([127.0.0.1:7714]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id FA/A8-39355-4C1E4925 for ; Tue, 26 Nov 2013 13:00:36 -0500 Authentication-Results: pb1.pair.com smtp.mail=john@bafford.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=john@bafford.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain bafford.com from 96.241.205.2 cause and error) X-PHP-List-Original-Sender: john@bafford.com X-Host-Fingerprint: 96.241.205.2 nova.zort.net Received: from [96.241.205.2] ([96.241.205.2:54040] helo=nova.zort.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/57-39355-440E4925 for ; Tue, 26 Nov 2013 12:54:14 -0500 Received: from [10.0.0.180] (74-95-80-113-WashingtonDC.hfc.comcastbusiness.net [74.95.80.113]) (authenticated bits=0) by nova.zort.net (8.14.5/8.14.5) with ESMTP id rAQHs7r7009063 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Tue, 26 Nov 2013 12:54:07 -0500 Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) In-Reply-To: Date: Tue, 26 Nov 2013 12:54:07 -0500 Cc: Chris London , Mats Lindh , "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: <6E5B1A3F-43B5-4064-9C18-2CBD0D696AFF@bafford.com> References: To: Paul Dragoonis X-Mailer: Apple Mail (2.1510) Subject: Re: [PHP-DEV] [Proposal] Modification to ?: functionality From: john@bafford.com (John Bafford) On Nov 26, 2013, at 12:41, Paul Dragoonis wrote: > On Tue, Nov 26, 2013 at 4:58 PM, Chris London = wrote: >=20 >> On Tue, Nov 26, 2013 at 8:15 AM, Mats Lindh = wrote: >>=20 >>> On Tue, Nov 26, 2013 at 3:43 PM, Chris London = wrote: >>>=20 >>>> I believe these two statements are functionally equivalent: >>>>=20 >>>> $foo =3D $foo ? $foo : 'default'; >>>> $foo =3D $foo ?: 'default'; >>>=20 >>> They are. >>>=20 >>> I would like to change it so it also checks for isset() so I propose = the >>>> following would be functionally equivalent: >>>>=20 >>>> $foo =3D isset($foo) && $foo ? $foo : 'default'; >>>> $foo =3D $foo ?: 'default'; >=20 > We can't change the behaviour of ?: that ship has already sailed, = we'll > just be hurting existing codebases on upgrading and more user = education is > required to understand non-visual changes in syntax like this, lets = try to > learn from our mistakes by not changing 'behaviour' anymore. >=20 > An alternative syntax that is similar and not ugly would be good since = the > ?: behaviour was broken from the start since you still need to run = isset() > before running ?: which was the problem we tried to solve in the first > place but it just didn't happen. >=20 > I don't like the @ symbol it's too different from what's already there = on > the ternary logic. >=20 > Proposal: $foo =3D $arr['value'] ?:: ""; >=20 > Thoughts? What if it was: $foo ?? $trueVal : $falseVal; with the shortened form being: $foo ??: $falseVal; This would make the isset($foo) && $foo functionality available for the = three operand version of ??:, and by making the ? the operator that's = doubled in that case would make it more clear when reading as to what's = going on (and maybe make it easier to parse?). -John >=20 >>=20 >>> The would break the assumption that a reference to an uninitialized = value >>> would generate a notice, unless explicitly handled in the logic. >>>=20 >>> While I also would like to have something similar to ?: to handle = default >>> values for array keys, etc., this would change a fundamental = assumption >>> that as been in place for many years now. I'm not sure if that's a = BC >> break >>> that would be acceptable this late. An alternative operator may be = more >>> suitable. >>>=20 >>=20 >> What do you think about using: >>=20 >> $foo =3D $foo @: 'default'; >>=20 >> and possibly >>=20 >> $foo @=3D 'default'; >>=20 >>=20 >>=20 >>>=20 >>> The change proposed has also been discussed several times since the >>> implementation of ?:. See the ifsetor-RFC: >>>=20 >>> https://wiki.php.net/rfc/ifsetor >>>=20 >>> It also contains links to the discussion around the feature back = then. >>>=20 >>> --mats