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 ```