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 <rowan.coll...@gmail.com>
wrote:

> On 11 July 2017 16:02:18 BST, Mark Shust <m...@shust.com> wrote:
> >For a syntactic
> >sugar/improvement, this can be shorthand for executing the loop instead
> >of
> >wrapping the block within an is_array check:
> >
> >
> ><?php
> >
> >$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]
>

Reply via email to