Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70403 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47561 invoked from network); 26 Nov 2013 14:59:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2013 14:59:11 -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 74.125.82.180 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 74.125.82.180 mail-we0-f180.google.com Received: from [74.125.82.180] ([74.125.82.180:64675] helo=mail-we0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/B1-39355-C37B4925 for ; Tue, 26 Nov 2013 09:59:09 -0500 Received: by mail-we0-f180.google.com with SMTP id u56so5364742wes.39 for ; Tue, 26 Nov 2013 06:59:06 -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=AqLQvlD5xsFezO+LeUOwqGxkJz2gLUl3nQoE04UaWoY=; b=bas8HXn/kFArWIgOL449R3h4ZTBVGe+xazvpoGZ1XV/zIZ4173t9JSjO3ou3VNgXCA JL9YTA9LAHtlQpNrBAl9CyFzHjv4wPl/XLqkbUnW4gHTjIvkxdVhEkWadZxy1DOuvjHu pLWgfu73bxO01GNwdVP0GnsPYxEKCc9nYWIUbXAzQ9ts/LwCiBp7RlNsVxV8UhMDyAdv ZYJLya9mGJQpirJweF2V/eAqGX1gWET9PViz1sD0ykvrY8HpHWt1/prNHXDKGvxASVbp +lz3skyJ7ixaaGMJ2dfo+ZQ2enUgm6fUmksOdTduZy9dHMDGQnGzm6obb/im0RdTUIql VF5A== X-Received: by 10.194.216.225 with SMTP id ot1mr424905wjc.80.1385477946348; Tue, 26 Nov 2013 06:59:06 -0800 (PST) MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.216.152.70 with HTTP; Tue, 26 Nov 2013 06:58:46 -0800 (PST) In-Reply-To: References: Date: Tue, 26 Nov 2013 15:58:46 +0100 X-Google-Sender-Auth: R2hGN5PMRhflHgG7nhm0SFOZYds Message-ID: To: Chris London Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c283b8d618cf04ec15b854 Subject: Re: [PHP-DEV] [Proposal] Modification to ?: functionality From: colder@php.net (Etienne Kneuss) --001a11c283b8d618cf04ec15b854 Content-Type: text/plain; charset=UTF-8 Hi Chris, On Tue, Nov 26, 2013 at 3:43 PM, Chris London wrote: > I find in a lot of my code I have ternaries that set default values. I > also find that I can't use the ?: syntax for one reason and one reason > only. It throws a notice if the value isn't set. > > I believe these two statements are functionally equivalent: > > $foo = $foo ? $foo : 'default'; > > $foo = $foo ?: 'default'; > > 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'; > > I would be happy to see a patch for that, last time I checked it was hard to make the grammar happy with this change. Note that it's not necessarily a variable. It should have no impact on: $foo = gee() ?: "default"; > Random addition: what if we also allowed the following shorthand? > > $foo ?= 'default'; > > or possibly: > > $foo ?:= 'default'; > > Thanks everyone, > Chris > -- Etienne Kneuss http://www.colder.ch --001a11c283b8d618cf04ec15b854--