2009/11/16 Mathieu Suen <mathieu.s...@easyflirt.com>: > Maybe you find it useless. That is just a discussion. I don't expect PHP to > change thought it should IMHO, especially now that you are introducing > closure. :) > > For those who complain about the foreach behavior (including me) that's > typically a scope issue. Doing an automatic unset isn't the right way of > solving it. > Somehow this foreach exemple show why you don't want dynamic scoping. > > Victor Bolshov a écrit : >> >> That's a completely useless discussion, isn't it? Whoever is "right" >> with his opinion regarding scoping - nobody will (and nobody would >> like to) change PHP's scoping for those reasons as it would break too >> much existing code. >> >> 2009/11/16 Mathieu Suen <mathieu.s...@easyflirt.com>: >>> >>> Etienne Kneuss a écrit : >>>> >>>> Hello, >>>> >>>> On Mon, Nov 16, 2009 at 2:10 PM, Mathieu Suen >>>> <mathieu.s...@easyflirt.com>wrote: >>>> >>>>> Pierre Joye a écrit : >>>>> >>>>> On Mon, Nov 16, 2009 at 12:07 PM, Mathieu Suen >>>>>> >>>>>> <mathieu.s...@easyflirt.com> wrote: >>>>>> >>>>>> • Pensez à l'environnement, n'imprimez cet e-mail qu'en cas de réelle >>>>>>> >>>>>>> nécessité >>>>>>> >>>>>> Discussing endlessly an issue only because you do not understand it is >>>>>> also an environmental problem, please consider to read the manual and >>>>>> stop to use every single channel to ask the same questions again and >>>>>> again. >>>>>> >>>>>> Salutations, >>>>>> >>>>> That's not a question, look at what lisp dose and scheme. >>>>> Look at the lambda calculus etc. >>>>> >>>>> The variable inside the foreach should not be captured outside. >>>>> Like function argument. And again and again you are doing the same >>>>> mistake: >>>>> >>>> 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). >>> >>> I 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; } >>> >>> What'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... >>> >>> There is only an >>>> >>>> assign statement, that may introduce a new variable, or not. Without >>>> such >>>> a >>>> declaration statement, static scoping doesn't make much sense. >>>> >>>> For example: >>>> >>>> if (..) { $a = 2; } else { $a = 3; } >>>> >>>> echo $a; >>>> >>>> would either fail or require some branch analysis at compile time to >>>> work. >>>> which we can't really afford. >>>> >>>> Or: >>>> >>>> $a = 2; >>>> >>>> if (...) { $a = 3; } >>>> >>>> There is no way of stating whether $a = 3; should be for a $a that is >>>> unrelated to the outer $a. >>>> >>>> >>>> In other words, the kind of scoping you want will most likely never be >>>> implemented in PHP. >>>> >>>> Best >>>> >>>> >>>>> "Dynamic scoping is primarily interesting as a historical mistake: it >>>>> was >>>>> in the earliest versions of Lisp, >>>>> and persisted for well over a decade. Scheme was created as an >>>>> experimental >>>>> language in part to experiment >>>>> with static scope. This was such a good idea that eventually, even >>>>> Common >>>>> Lisp adopted static scope. >>>>> Most modern languages are statically scoped, but sometimes they make >>>>> the >>>>> mistake of recapitulating this >>>>> phylogeny. So-called “scripting” languages, in particular, often make >>>>> the >>>>> mistake of implementing dynamic >>>>> scope (or the lesser mistake of just failing to create closures), and >>>>> must >>>>> go through multiple iterations before >>>>> they eventually implement static scope correctly." >>>>> - Shriram Krishnamurthi, "Programming Languages: >>>>> Application and Interpretation" section 6.5: >>>>> >>>>> -- Mathieu Suen >>>>> >>>>> >>>>> >>>>> -- >>>>> PHP Internals - PHP Runtime Development Mailing List >>>>> To unsubscribe, visit: http://www.php.net/unsub.php >>>>> >>>>> >>>> >>> >>> -- Mathieu Suen >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> > > > -- Mathieu Suen > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
Would an E_WARNING, or E_STRICT (maybe), be suitable here? <?php $array = array(1 => 'one', 2 => 'two', 3 => 'three'); foreach($array as $index => &$value) { echo "$index is $value\n"; } // MAYBE this like could generate an E_WARNING: variable $s previously used as a reference in file:... line:5 $value = 'Troi'; print_r($array); ?> Whilst the documentation is quite clear, I suspect a bit of hand-holding (in the form of an error of some type) could be appropriate. But even by my own standards (whatever they may be!) I think that looks dubious. Assigning a value to a reference supplied as a parameter to a function wouldn't be considered an error. So, extend this error to only be for foreach()'s ... Again, yuck, too specific (though mktime() warranted an error when there is _seemingly_ nothing wrong with it). Richard. -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php