Re: Lexical scoping

From: Date: Tue, 28 Jan 2014 14:05:22 +0000
Subject: Re: Lexical scoping
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-71671@lists.php.net to get a copy of this message
2014-01-28 Lazare Inepologlou <linepogl@gmail.com> > > 2014-01-28 Sebastian Krebs <krebs.seb@gmail.com> > > 2014-01-28 Andrea Faulds <ajf@ajf.me> >> >> > Good morning, >> > >> > Perhaps a future version of PHP (PHP 6? 5.7?) could have lexical scoping >> > with a >> > "let" keyword? At the very least, it would make foreach() with a >> reference >> > less >> > of a problem: >> > >> > foreach ($array as let &$a) { >> > $a = 3; >> > } >> > // $a is not in this scope - no need to worry about accidentally >> > changing >> > last array item >> > >> > Any thoughts? >> > >> >> Hi, >> >> My 2 cents: That is a very minor improvement at the cost of an additional >> keyword. It is only to avoid, that you accidentally interfere with outers >> scope variables? If it is hard to track these variables, maybe your >> method/function is too big. >> >> > I agree. > > >> Regarding your example: >> >> foreach ($array as &$a) { >> $a = 3; >> } >> $a = null; // $a not a reference anymore. Problem solved :) >> >> > Problem not solved. You have just changed the last element of $array... > This is the exact problem that was to be avoided. > Touche ;) then use unset(). This time I tried it before: http://codepad.viper-7.com/lOx1XL > > > Lazare INEPOLOGLOU > Ingénieur Logiciel > > > >> Regards, >> Sebastian >> >> >> > -- >> > Andrea Faulds >> > http://ajf.me/ >> > >> > -- >> > PHP Internals - PHP Runtime Development Mailing List >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > >> >> >> -- >> github.com/KingCrunch >> > > -- github.com/KingCrunch

« previous php.internals (#71671) next »