Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99840 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94428 invoked from network); 11 Jul 2017 17:50:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2017 17:50:30 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.128.180 mail-wr0-f180.google.com Received: from [209.85.128.180] ([209.85.128.180:35909] helo=mail-wr0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DC/C9-47109-4EF05695 for ; Tue, 11 Jul 2017 13:50:29 -0400 Received: by mail-wr0-f180.google.com with SMTP id c11so9119357wrc.3 for ; Tue, 11 Jul 2017 10:50:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=Rnbr3kqyyefeB5g5nwWd5Pcz7qCG1wSg96SstEMKhg0=; b=MdHTZRQT9IjkMxxW3d0aQomSwsPouwKNb8tgsXHq3oMh73PpE6Qd3weQkGeAbrKJmj VSUcBcR2uTIcPD8JPUXZqAOQednt+JnOj5akw3R3sxvqSBFdod3op5gOhZh/OXFr/7TR mi2WfObwg3jmAkQFsAEKEF56yZg45nZZind+zwRCoq/2K1WiwchrGds4XkiQeIi2DP8a hmo6RW4yptN4KTw+HjScMm54J14flJKw4gKOUuPGVO/U4ndEUbNT0mdXwVRdJJ9RRKCx 7tfS5xsrdplMFYRT9aIMm+wJTy52XC4RkJBCt5G+ztM5giw1DQAXXgZOhbeWgrjBwL2w vzpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=Rnbr3kqyyefeB5g5nwWd5Pcz7qCG1wSg96SstEMKhg0=; b=LL9Z3oJLg9BEMfXdE97BXzhRzWBloXbGjZJKFB36KMJB+G7Ot87FDcXMddXcTlVcS/ 77/ZEze0HdIP8B0rz1mOTgyDDO08G9h3Nh0SeBgL5x5tak+bzs6rg7+3QoJsL7A2DyxD nAWDLuKh3/3oHsl2/mhmyAupodGWcyAa+j0Eo/h4Tl8BaJshyDDCyIg0aHn0zEl0R5CE GwK+tvJWox3oGnFxKuwercjDsDexAkh9lz0SPuYsdFv0H4w7ZZXLOOuRpQI9Blu1VGN1 vudPJSXGFSfnB7xcJYfVkFSmMPXHaXCUulkKXfkLH9Au21nFdJpQVaC34NqWFvM1A9g8 9a8w== X-Gm-Message-State: AIVw112U7I2WSSqXeNjiXCfeJ9Aia/LluqDjVm+K0ej7u0r7GKO50+tG 9xscWEbx+UigZOxW5vE= X-Received: by 10.223.135.154 with SMTP id b26mr682934wrb.48.1499795425579; Tue, 11 Jul 2017 10:50:25 -0700 (PDT) Received: from [10.93.216.237] (94.197.120.2.threembb.co.uk. [94.197.120.2]) by smtp.gmail.com with ESMTPSA id m123sm3114131wmb.3.2017.07.11.10.50.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jul 2017 10:50:24 -0700 (PDT) Date: Tue, 11 Jul 2017 18:49:31 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net,Mark Shust Message-ID: Subject: Re: [PHP-DEV] array coalesce operator concept From: rowan.collins@gmail.com (Rowan Collins) 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 =3D "abc"; > >foreach (??$foo as $bar) { > > echo $bar; > >} Hi! I think there's definitely the start of a good idea here, but the syntax y= ou suggest doesn't read quite right=2E As has been pointed out, this differ= s from existing features in two ways: - the special handling is for any non-iterable value, not just null or emp= ty/falsey values, for which you could use $foo??[] and $foo?:[] respectivel= y - the handling is to skip the loop, not loop once assigning $bar to the sc= alar value, as would happen with (array)$foo The challenge, then, is to come up with some syntax that somehow suggests = these rules=2E The "??" is too much like the null coalesce, which would be = misleading=2E 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 someon= e else=2E Regards, --=20 Rowan Collins [IMSoP]