Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46546 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58052 invoked from network); 28 Dec 2009 10:44:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Dec 2009 10:44:42 -0000 X-Host-Fingerprint: 95.31.13.88 xdmitri2.static.corbina.ru Received: from [95.31.13.88] ([95.31.13.88:19946] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/5B-26502-91C883B4 for ; Mon, 28 Dec 2009 05:44:41 -0500 Message-ID: To: internals@lists.php.net References: <31.35.26502.C79573B4@pb1.pair.com> <1B.86.26502.42B673B4@pb1.pair.com> <4B3785AC.2000507@lerdorf.com> <8A.91.26502.CDB083B4@pb1.pair.com> <4B38106C.2080806@lerdorf.com> <4B382FB7.9080304@lerdorf.com> Date: Mon, 28 Dec 2009 13:44:37 +0300 Lines: 96 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5843 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-RFC2646: Format=Flowed; Original X-Posted-By: 95.31.13.88 Subject: Re: [PHP-DEV] Unsetting loop variables at the end of the loop From: dmda@yandex.ru ("jvlad") > jvlad wrote: >>> $a = array(1); >>> $b = 0; >>> $c = &$b; >>> foreach($a as $c); >>> Now you are arguing that $b should not be 1? >>> The two pieces of code are identical >> >> It's just a nightmare example. I wonder have you ever see anything like >> this >> in real life? >> Could you please let me see it too, for example in code.google.com? >> If you cann't, what are you fighting for? >> Interestingly, how many people will consider the code sample you >> demonstrated ugly... >> How many sporadic problems were already created and will be created just >> beacause >> of this unclear behavior of foreach? > > It isn't unclear. It is perfectly consistent. Whether it is ugly or > not is irrelevant. Even though you can kill somebody using hammer, does it mean that it _is_ the feature to be preserved in all future versions of the hammer? Also, you didn't answer why another function that is WIDELY used, is going to hell. Why don't you defend its features which go to hell with this function? Why don't you defent the language BC in this case? What does make your position so selective? Why a useless and harmful (yes it's harmful according to so many posts) feature is preserved while uselfull and needed function is going away? > >>> And I don't see how your prev/next stuff has anything to do with this. >> >> >> Ok. What my stuff has to do with this is there: >> If prev/next were consistent with foreach, they would return first/last >> element of the >> array respectively as soon as they reached the boundary. But no! They >> return >> FALSE. > > Which has nothing to do with the question at hand here. We are talking > about breaking any reference in the variables used in the loop > construct. We are not talking about any other behaviour here. Please have a look at this page http://www.php.net/manual/en/control-structures.foreach.php It's where you can find the following: ------------------------------------------------------------------------------ You may have noticed that the following are functionally identical: \n"; } foreach ($arr as $value) { echo "Value: $value
\n"; } ?> ------------------------------------------------------------------------------ I checked and it appears that they are not identical, quite the opposite, they expose the difference I mentioned before. Each() assigns NULL to the value after the array pointer reached end. ForEach() stays with last element in this case: compare the output: \n"; } var_dump($value); ?> \n"; } var_dump($value); ?> -jv