Re: Lexical scoping
2014-01-28 Andrea Faulds <[email protected]>
> 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
Thread (11 messages)