Re: Lexical scoping

From: Date: Tue, 28 Jan 2014 12:31:30 +0000
Subject: Re: Lexical scoping
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-71667@lists.php.net to get a copy of this message
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. Regarding your example: foreach ($array as &$a) { $a = 3; } $a = null; // $a not a reference anymore. Problem solved :) 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

« previous php.internals (#71667) next »