Speaking of, i hope that one day we can support javascript-style let in php
:) like
foreach($it as let &$v){}
but that's a discussion for another thread (and i'm sure it has been
discussed before, i haven't actually checked though)

On Sat, 14 Aug 2021 at 15:23, Hossein Baghayi <hossein.bagh...@gmail.com>
wrote:

> On Fri, 13 Aug 2021 at 17:59, Nikita Popov <nikita....@gmail.com> wrote:
>
> > I'd like to address a common footgun when using foreach by reference:
> > https://wiki.php.net/rfc/foreach_unwrap_ref
> >
>
> Hello,
> I had a question regarding this.
> Wouldn't it be possible to limit ```$value```'s scope to only foreach's
> block then discard it? Unless it was already defined elsewhere.
>
> ```
> foreach($nice_stuff as &$value) {} //we are done here and no need to keep
> value around.
>
> echo $value; // $value is Undefined here.
>
> $value = null;
> foreach($stuff as &$value) {} //we can keep the value here since it doesn't
> belong to foreach.
>
> echo $value; // prints some fancy pancy stuff
> ```
>

Reply via email to