Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99841 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98624 invoked from network); 11 Jul 2017 19:06:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2017 19:06:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=mark@shust.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mark@shust.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain shust.com from 209.85.218.52 cause and error) X-PHP-List-Original-Sender: mark@shust.com X-Host-Fingerprint: 209.85.218.52 mail-oi0-f52.google.com Received: from [209.85.218.52] ([209.85.218.52:33304] helo=mail-oi0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/3A-47109-EA125695 for ; Tue, 11 Jul 2017 15:06:23 -0400 Received: by mail-oi0-f52.google.com with SMTP id p188so1241581oia.0 for ; Tue, 11 Jul 2017 12:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shust-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=l8NGJN7Luaf15EpGIi5045E6eLByR+gYf0KU7Q8HvMw=; b=b+D1z6PukS+iAGJs7Byir0MMSn6R6XAlGC9EMSQ9PUKCtyvrGvsDyiaEI71W0J0djl emzF7d7HhPAkMvskgg9LTJH8EGm3wUJ0KAI3W7aZxSsLitn/M3Br0iF7BVaD4wt+XMr8 aFSPKAdDGltO07Ing0u03hlRndmsknOZqQiAwIaBK0J+1gkJKr9z6VUHWyPjbAnmx3X1 ILXwubzdEUJmKEz1a1MxfFqrotg0ZX+Qs1TfxqaYyc3sgK/8WsgeXl67FVc/23C8eMHx ColZm7M3TivWj32AeMwdr7mlPOgM99MyEQ7G5tykEyXkM1L5wxYe1BrMW6J8Rkna6zk1 IpYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=l8NGJN7Luaf15EpGIi5045E6eLByR+gYf0KU7Q8HvMw=; b=InqzP3eQ65SUR12/0H7u6oysQ7Y//0MtmSmZgFEV75DiKwb3QlLGZhpdLzyVbNIVV7 gTPggWIiFmXIONiQtoBBP/drSqq17vLB/vmiMrZI9wBILbpHtqZOyQqiwsXBU4Ijk1lm 0ZB8kZebvT3wnaYDIOqv8MF7X23HuKDwfdjl1O+aRZVQiR8/qJa0s8s4JBnuJnvQMZm7 6sYfoz5jijlJxir5JX+UFVbRSFgfuYsAuDVehcwcsWrKkGa9a6Jt/47i+Ax25GThA7Z/ 9Nd+Z/4aDaW2bcBTZXqSyAdrR63twmTWqeE86OmUPInAc4UX4DVT9piE2gVpR7xG2gHx 0bNQ== X-Gm-Message-State: AIVw112jPpdxlZ04CvKQ26aAVGVKBMd0l8WECCqJN7RQg2PeCO7Ejq1K mldb+/TQu5OQAE6V/IauRLXBvIhqLiUT X-Received: by 10.202.106.6 with SMTP id f6mr1154284oic.85.1499799979413; Tue, 11 Jul 2017 12:06:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 11 Jul 2017 19:06:08 +0000 Message-ID: To: Rowan Collins , internals@lists.php.net Content-Type: multipart/alternative; boundary="001a1141b11a01fa3e05540f65d5" Subject: Re: [PHP-DEV] array coalesce operator concept From: mark@shust.com (Mark Shust) --001a1141b11a01fa3e05540f65d5 Content-Type: text/plain; charset="UTF-8" Thanks for the great feedback. Based on the last mindset on keyword syntax, this comes to mind, intended to be used similarly to the 'use' keyword when used within the context of a closure: foreach ($foo as $bar) if (is_array) { ... } I don't think this is a vast improvement over wrapping this within an is_array check, however it does avoid the additional nest/wrapping. I was hoping for something that reads a bit more concisely or with a bit more syntactical sugar than the above. I think this does read nicely though. Cheers, Mark On Tue, Jul 11, 2017 at 1:50 PM Rowan Collins wrote: > On 11 July 2017 16:02:18 BST, Mark Shust wrote: > >For a syntactic > >sugar/improvement, this can be shorthand for executing the loop instead > >of > >wrapping the block within an is_array check: > > > > > > > > >$foo = "abc"; > > > >foreach (??$foo as $bar) { > > > > echo $bar; > > > >} > > Hi! > > I think there's definitely the start of a good idea here, but the syntax > you suggest doesn't read quite right. As has been pointed out, this differs > from existing features in two ways: > > - the special handling is for any non-iterable value, not just null or > empty/falsey values, for which you could use $foo??[] and $foo?:[] > respectively > - the handling is to skip the loop, not loop once assigning $bar to the > scalar value, as would happen with (array)$foo > > The challenge, then, is to come up with some syntax that somehow suggests > these rules. The "??" is too much like the null coalesce, which would be > misleading. > > The only idea that immediately comes to mind is a keyword: > > foreach ifarray ($foo as $bar) { > > I can't say I'm that keen on that syntax, but maybe it will inspire > someone else. > > Regards, > > -- > Rowan Collins > [IMSoP] > --001a1141b11a01fa3e05540f65d5--