Re: [PHP-DEV] Unwrap reference after foreach

2021-08-26 Thread Nikita Popov
On Sat, Aug 14, 2021 at 6:00 PM Claude Pache wrote: > > Le 13 août 2021 à 15:28, Nikita Popov a écrit : > > Hi internals, > > I'd like to address a common footgun when using foreach by reference: > https://wiki.php.net/rfc/foreach_unwrap_ref > > This addresses the issue described in the big red

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-16 Thread Michael Wallner
> > This seems like a good opportunity to go one step further and have loops > create a new scope, which would automagically handle the unwrapping with out > worrying about the edge cases. Obviously, this would be a bigger BC break, > but one worth considering. > Sounds reasonable, but this

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-14 Thread Claude Pache
> Le 13 août 2021 à 15:28, Nikita Popov a écrit : > > Hi internals, > > I'd like to address a common footgun when using foreach by reference: > https://wiki.php.net/rfc/foreach_unwrap_ref > > This addresses the issue described in the big red box at >

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-14 Thread Hans Henrik Bergan
well today you can do foreach($it as &$value){...} unset($value); - which is pretty close, but it will break with $value="initial";foreach($it as &$value){...}unset($value); echo $value; here $value will not be "initial", it will be undefined, however you *CAN* do

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-14 Thread Hans Henrik Bergan
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 wrote: > On Fri,

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-14 Thread Hossein Baghayi
On Fri, 13 Aug 2021 at 17:59, Nikita Popov 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

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-13 Thread Trevor Rowbotham
Original Message On Aug 13, 2021, 9:28 AM, Nikita Popov < nikita@gmail.com> wrote: Hi internals, I'd like to address a common footgun when using foreach by reference: https://wiki.php.net/rfc/foreach_unwrap_ref This addresses the issue described in the big red box at

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-13 Thread Tobias Nyholm
I’m happy with this too. I’m +1 for most things that makes a smoother developer experience. //Tobias Nyholm > On 13 Aug 2021, at 06:44, Hans Henrik Bergan wrote: > > +1 from me, and yeah lets not care about that edge case, i hope the edge > gets removed at some point.. (but that's an issue

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-13 Thread Flávio Heleno
On Fri, Aug 13, 2021 at 11:20 AM Claude Pache wrote: > > > Le 13 août 2021 à 15:28, Nikita Popov a écrit : > > > > Hi internals, > > > > I'd like to address a common footgun when using foreach by reference: > > https://wiki.php.net/rfc/foreach_unwrap_ref > > > > This addresses the issue

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-13 Thread Claude Pache
> Le 13 août 2021 à 15:28, Nikita Popov a écrit : > > Hi internals, > > I'd like to address a common footgun when using foreach by reference: > https://wiki.php.net/rfc/foreach_unwrap_ref > > This addresses the issue described in the big red box at >

Re: [PHP-DEV] Unwrap reference after foreach

2021-08-13 Thread Hans Henrik Bergan
+1 from me, and yeah lets not care about that edge case, i hope the edge gets removed at some point.. (but that's an issue for another thread) FWIW if attempts at getting it in 8.2 fails, i would welcome another attempt at this for PHP9 On Fri, 13 Aug 2021 at 15:29, Nikita Popov wrote: > Hi

[PHP-DEV] Unwrap reference after foreach

2021-08-13 Thread Nikita Popov
Hi internals, I'd like to address a common footgun when using foreach by reference: https://wiki.php.net/rfc/foreach_unwrap_ref This addresses the issue described in the big red box at https://www.php.net/manual/en/control-structures.foreach.php. While this is "not a bug" (as our bug tracker can