Re: Unwrap reference after foreach

From: Date: Fri, 13 Aug 2021 14:49:02 +0000
Subject: Re: Unwrap reference after foreach
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-115706@lists.php.net to get a copy of this message
On Fri, Aug 13, 2021 at 11:20 AM Claude Pache <claude.pache@gmail.com> wrote: > > > Le 13 août 2021 à 15:28, Nikita Popov <nikita.ppv@gmail.com> 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 > > > > https://www.php.net/manual/en/control-structures.foreach.php. While > this is > > "not a bug" (as our bug tracker can regularly attest), it's rather > > unexpected, and we could easily avoid it... > > > > Regards, > > Nikita > > > Hi, > > I don’t like the split of semantics between simple and complex variables. > It makes the language more inconsistent, therefore more difficult to reason > about. > > On the other hand, using a complex variable as reference in that context > should be very rare outside obfuscation code contests. > > Therefore, I suggest to deprecate (and later remove) the ability to use of > a complex variable as reference in that context. That would solve the > inconsistency issue. > > —Claude > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > Hi, I know I don't have an actual vote (voting karma it is), but it's a +1 from me as well. I like Trevor's suggestion of scoping variables within loops and this would be a first step towards it.

« previous php.internals (#115706) next »