Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70415 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71974 invoked from network); 26 Nov 2013 17:48:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2013 17:48:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.169 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.212.169 mail-wi0-f169.google.com Received: from [209.85.212.169] ([209.85.212.169:56429] helo=mail-wi0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 37/A6-39355-1EED4925 for ; Tue, 26 Nov 2013 12:48:17 -0500 Received: by mail-wi0-f169.google.com with SMTP id hm6so6211068wib.4 for ; Tue, 26 Nov 2013 09:48:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=nQDWsaInPqpqgc4PCRgMmR0Sf2qGOg+aygIHNP5G4k8=; b=u+fsXTqYtU5ax2j7jbHKari+H34CxxoL9wLjt6BVgHVVxeHpyEKPptgNRE5ZzyQQPf P9rGNIe60PXHIuDu//SMpQRiAWL9fztG2wupNuS/SkvKigEOsVAxZ5fnog4Y9ZXInBCL XUdfdjLw/lVgiQr5pDthONLQlVFiuoyTWveM/PqPseBHmNzylheUotdVWkBh1Dd4PlGb tZRakmbLkcTvse8VYan+DAr68Jby6rH9zmw3UNjCRF3EpszNyq9rnC0dBMZoM2YEvl6a bMN4h99IQEGceyDL8/lYvE+RFm0KIDpcIgsDcQG4zYo2ThmwgG4kV3DoIHdnbiL5yrqk snfw== X-Received: by 10.194.5.7 with SMTP id o7mr27836061wjo.17.1385488094460; Tue, 26 Nov 2013 09:48:14 -0800 (PST) MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.216.152.70 with HTTP; Tue, 26 Nov 2013 09:47:54 -0800 (PST) In-Reply-To: References: Date: Tue, 26 Nov 2013 18:47:54 +0100 X-Google-Sender-Auth: PaS1JRejBLpLcNY9UGWk-Z0uot8 Message-ID: To: Paul Dragoonis Cc: Chris London , Mats Lindh , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b5d8d45b6042804ec181587 Subject: Re: [PHP-DEV] [Proposal] Modification to ?: functionality From: colder@php.net (Etienne Kneuss) --047d7b5d8d45b6042804ec181587 Content-Type: text/plain; charset=UTF-8 On Tue, Nov 26, 2013 at 6: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. > I disagree, I think removing a case for a Notice is the kind of BC break we can allow, especially in major versions. We should aim at making the language easier to use for day to day cases, and I think this change goes in that direction. > > 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 > > > > > > -- Etienne Kneuss http://www.colder.ch --047d7b5d8d45b6042804ec181587--