Re: Variable scopes for language constructs (foreach, ...)
| From: | Adam Harvey | Date: | Tue, 28 Jun 2011 10:22:32 +0000 |
| Subject: | Re: Variable scopes for language constructs (foreach, ...) | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53608@lists.php.net to get a copy of this message | ||
On 28 June 2011 18:08, Dave Ingram <dave@dmi.me.uk> wrote:
> So what about modifying the loop syntax slightly, to explicitly scope a
> variable in a foreach? Or would this be problematic/counter-intuitive too?
>
> foreach ($abc as var $def) {
> }
>
> and
>
> foreach ($abc as var &$def) {
> }
PHP's scoping behaviour — particularly around foreach loops and
references — confuses the hell out of people already. I don't think
adding another optional mode that's triggered by a keyword is going to
make that any less confusing, frankly.
Adam