Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70423 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85309 invoked from network); 26 Nov 2013 18:12:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2013 18:12:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@chrislondon.co; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@chrislondon.co; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain chrislondon.co does not designate 74.125.82.169 as permitted sender) X-PHP-List-Original-Sender: me@chrislondon.co X-Host-Fingerprint: 74.125.82.169 mail-we0-f169.google.com Received: from [74.125.82.169] ([74.125.82.169:52306] helo=mail-we0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/A9-39355-5A4E4925 for ; Tue, 26 Nov 2013 13:12:54 -0500 Received: by mail-we0-f169.google.com with SMTP id w61so41104wes.0 for ; Tue, 26 Nov 2013 10:12:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=j1SUELgWZzDnh9IpgGYsMkc8smbXN/nfpsNCPgrH+Hw=; b=cR1NrxeukrY+pGKkfkZ3A4YMNMv/bxDZt2hl9PXwnIKBS+RpGtcreaU3EoODu5S/Mc WzVUqMklz7Aw541w6XgqTJ8mCnymbSQ6XZfTB82GWjuECGl5zEA7/ulbW5mL6VpN2I3e u43Unc07/qjYcziPiWjpQlvSep3VWK7K9jfCLnqD+MrGENEGu+gnypjmQXl8cwHIx0V4 5GH4QQ0nNlgJRhgaLUVpVsovHBSBzT1AqZCcS3zBz9HbYo4GQraM6vr2IZak06do2y5L ihRmsu5N1Ebv3Y5rl2DDy7roM5B2g8uWl+Bl82kAf6aTP24puwdjaGXXd2pIAE044G17 UfYw== X-Gm-Message-State: ALoCoQmvqdPCjgZr1hvQo0FpriYr1tQwjjiyKHjoZ0fp9BsfM3CEBiisNTedLu5BfA03Qz7GbMiw MIME-Version: 1.0 X-Received: by 10.180.75.235 with SMTP id f11mr19238277wiw.27.1385489570827; Tue, 26 Nov 2013 10:12:50 -0800 (PST) Received: by 10.217.153.135 with HTTP; Tue, 26 Nov 2013 10:12:50 -0800 (PST) X-Originating-IP: [66.219.207.210] In-Reply-To: References: Date: Tue, 26 Nov 2013 11:12:50 -0700 Message-ID: To: Etienne Kneuss Cc: Philip Sturgeon , Paul Dragoonis , Mats Lindh , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d043c81bab599b004ec186d75 Subject: Re: [PHP-DEV] [Proposal] Modification to ?: functionality From: me@chrislondon.co (Chris London) --f46d043c81bab599b004ec186d75 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Nov 26, 2013 at 11:08 AM, Etienne Kneuss wrote: > > > > On Tue, Nov 26, 2013 at 6:57 PM, Philip Sturgeon wrote: > >> On Tue, Nov 26, 2013 at 12:41 PM, Paul Dragoonis >> wrote: >> > On Tue, Nov 26, 2013 at 4:58 PM, Chris London >> wrote: >> > >> >> On Tue, Nov 26, 2013 at 8:15 AM, Mats Lindh >> wrote: >> >> >> >> > On Tue, Nov 26, 2013 at 3:43 PM, Chris London >> wrote: >> >> > >> >> >> I believe these two statements are functionally equivalent: >> >> >> >> >> >> $foo = $foo ? $foo : 'default'; >> >> >> >> >> >> $foo = $foo ?: 'default'; >> >> >> >> >> > >> >> > They are. >> >> > >> >> > >> >> > I would like to change it so it also checks for isset() so I propose >> the >> >> >> following would be functionally equivalent: >> >> >> >> >> >> $foo = isset($foo) && $foo ? $foo : 'default'; >> >> >> >> >> >> $foo = $foo ?: 'default'; >> >> >> >> >> >> > >> > 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. >> > >> > 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. >> > >> > I don't like the @ symbol it's too different from what's already there >> on >> > the ternary logic. >> > >> > Proposal: $foo = $arr['value'] ?:: ""; >> > >> > Thoughts? >> > >> >> >> >> > The would break the assumption that a reference to an uninitialized >> value >> >> > would generate a notice, unless explicitly handled in the logic. >> >> > >> >> > 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. >> >> > >> >> >> >> What do you think about using: >> >> >> >> $foo = $foo @: 'default'; >> >> >> >> and possibly >> >> >> >> $foo @= 'default'; >> >> >> >> >> >> >> >> > >> >> > The change proposed has also been discussed several times since the >> >> > implementation of ?:. See the ifsetor-RFC: >> >> > >> >> > https://wiki.php.net/rfc/ifsetor >> >> > >> >> > It also contains links to the discussion around the feature back >> then. >> >> > >> >> > --mats >> >> > >> >> >> >> This seems like a cracking time to suggest: >> >> $x ||= $y; >> >> The difference? Anything left of the ? SHOULD fail if it is not set, >> because you are using it in a condition which is dangerous and odd for >> other types of condition, but adding in this new syntax (similar to >> Ruby) would essentially evaluate to this: > > >> empty($x) ? $y : $x; >> >> This gives keeps the behavior of ternary operators working in the same >> way, but adds what we want: the ability to nicely set defaults for >> variables and array keys that may not be set. >> > > To me this reads as $x = $x || $y like all the = binary operators. So > it would definitely feel weird to use that syntax for something else... > I really like that. I do stuff like that in Javascript right now. > > >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > -- > Etienne Kneuss > http://www.colder.ch > --f46d043c81bab599b004ec186d75--