Stas,
Wow, for some reason it didn't occur to me to try that. Confirming the
following works:
foreach ($foo ?? [] as $bar) {
echo $bar;
}
I think the biggest need for this is if the value is null. Guess it's
case-closed :)
Might be a good idea to add this to the docs, pretty neat.
Mark
ything failing in the entire loop block.
>
> If we're going to introduce this behaviour, let's get it right ;-) (even
> if we don't like it ourselves)
>
> Kind regards,
> Aidan
>
> On 12 July 2017 at 16:26, MichaĆ Brzuchalski > wrote:
>
>> 12.07.2017
> Kind regards,
> Aidan
>
> On 12 July 2017 at 02:50, Mark Shust wrote:
>
>> Aidan,
>>
>> Fantastic suggestion (@as) -- that is really the succinctness I was
>> initially looking for, and I think the intention makes a lot of sense. My
>> only concern/is
prevent skip past execution of the entire foreach block if there is
> an error using $foo as an array. So might make most sense to place the `@`
> on `as`, IMO, but I guess arguments could be made to place it like
> `@foreach ($foo as $bar)` or `foreach @($foo as $bar)`.
>
>
> Re
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 = "a
Hello,
I wanted to garnish feedback on a RFC proposal. This is just a concept at
this point, and is inspired by the null coalesce operator.
Code will error if a non-array value is passed through a looping feature.
For example, this code: