Re: Variable scopes for language constructs (foreach, ...)
| From: | Dave Ingram | Date: | Tue, 28 Jun 2011 10:08:53 +0000 |
| Subject: | Re: Variable scopes for language constructs (foreach, ...) | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53606@lists.php.net to get a copy of this message | ||
On 06/23/11 21:48, John Crenshaw wrote:
>> I think proposed change is extremely counter intuitive to the design
>> of PHP in regard to scoping and would be a very large bc break, PHP is
>> doing exactly what it is suppose to do here and I wouldn't want it any
>> other way.
> Agreed. Although I generally favor the idea of strong scope, it isn't
practical to implement in PHP. It isn't sensible because PHP doesn't
require explicit variable declaration, and the BC break would be crippling.
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) {
}
Dave