Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70414 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69328 invoked from network); 26 Nov 2013 17:41:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2013 17:41:13 -0000 Authentication-Results: pb1.pair.com header.from=dragoonis@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dragoonis@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.44 as permitted sender) X-PHP-List-Original-Sender: dragoonis@gmail.com X-Host-Fingerprint: 209.85.128.44 mail-qe0-f44.google.com Received: from [209.85.128.44] ([209.85.128.44:50154] helo=mail-qe0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/06-39355-83DD4925 for ; Tue, 26 Nov 2013 12:41:12 -0500 Received: by mail-qe0-f44.google.com with SMTP id nd7so5403916qeb.17 for ; Tue, 26 Nov 2013 09:41:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=5/Ucm9GnS+nymqApdFdSx0ZT48B0p3scyASgUtkhHmU=; b=znY+IBriJaYBmaUs3WcfjaCU4bHQtd/1IIAcjGF51deXg46jtsU2qgNKLB/xNHN6n/ XrA648Atucmg+nzg+ng+k3T1p6VEs+srRwV9mekARhc42uNERwcK9tr//7Ra8bBQz01e VUR6b93liVkyO/A1jo0joTyZpZkM97sy8Ya3kkXpSHRzFrz8FRpvpQiK+MugA/6ksYPL o3AFbGJ1Nmey7p+WuEZID+ocEv2MjRk1lKmQmlF0q+McomN+P2rWjb3PxCuEMVZtTb9X w0I7O9At+qZdRyuqMpE2g5Y8F1VV8jjQuOFKDMVQCkXvlihtGP0tFEmfNvN08zSGlhpi UO6A== MIME-Version: 1.0 X-Received: by 10.224.66.5 with SMTP id l5mr59159435qai.31.1385487670002; Tue, 26 Nov 2013 09:41:10 -0800 (PST) Received: by 10.229.233.198 with HTTP; Tue, 26 Nov 2013 09:41:09 -0800 (PST) In-Reply-To: References: Date: Tue, 26 Nov 2013 17:41:09 +0000 Message-ID: To: Chris London Cc: Mats Lindh , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c2b762694a5f04ec17fc7e Subject: Re: [PHP-DEV] [Proposal] Modification to ?: functionality From: dragoonis@gmail.com (Paul Dragoonis) --001a11c2b762694a5f04ec17fc7e Content-Type: text/plain; charset=ISO-8859-1 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 > > > --001a11c2b762694a5f04ec17fc7e--