Re: bug when using foreach with references?
| From: | Mathieu Suen | Date: | Mon, 16 Nov 2009 15:34:42 +0000 |
| Subject: | Re: bug when using foreach with references? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-46064@lists.php.net to get a copy of this message | ||
Etienne Kneuss a écrit :
Hello, On Mon, Nov 16, 2009 at 2:51 PM, Mathieu Suen <mathieu.suen@easyflirt.com>wrote:Yes true, you need to distinguish declaration and assignment. Mixing them in the same syntax is not a good idea. But you could still do : $a = 2; if (..) { &$a = 3; } But I don't really like it either.Etienne Kneuss a écrit : Hello,You simply cannot take $a = ..; as a variable declaration, otherwise $a = 2; if (..) { $a = 3; } echo $a; would output 2, which is wrong.On Mon, Nov 16, 2009 at 2:10 PM, Mathieu Suen <mathieu.suen@easyflirt.comI am pretty sure you can have static scoping without declaration statement. Or you can consider "$a = 2" as a declaration statement. Which imply that if (..) { $a = 2; } else { $a = 3; } Produce 2 bindings of $a or can be a free if you 'declare' it outside . As: $a = null; if (..) { $a = 2; } else { $a = 3; }*SKIP*Static scoping is closely related to variable declaration. In PHP, there is no such thing as a variable declaration statement (apart from function arguments or class members, which are correcly scoped).
In fact, you haven't really solved any of the two problems I described.I don't know if that's the right paradigm. What about continuation passing style? :) -- Mathieu SuenWhat's strange is that part of the language is statically scoped will the other part is dynamic. See function vs. if, loop statement. Even worst if you think of the $_GET variable which should have a special scope...It's not strange, PHP does not have specific scopes for control structures, and $_GET/$_POST can be considered as global variables. Of course it may not be like language X or Y, but it makes sense considering the paradigm behind variables in PHP.