Re: foreach weirdness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12-03-24 11:15 AM, Al wrote:


On 3/23/2012 10:11 PM, Robert Cummings wrote:
On 12-03-23 06:30 PM, Simon Schick wrote:
2012/3/23 Robert Cummings<robert@xxxxxxxxxxxxx>

On 12-03-23 11:16 AM, Arno Kuhl wrote:


it still does not produce the correct result:
0 1 3 6 10 15 21
0 1 3 6 10 15 15


This looks like a bug... the last row should be the same. What version of
PHP are you using? Have you checked the online bug reports?



Hi, Robert

Does not seem like a bug to me ...
http://schlueters.de/blog/archives/141-References-and-foreach.html

What you should do to get the expected result:
Unset the variable after you don't need this reference any longer.

Ah yes... that clued me in. I disagree with the article's generalization with
respect to references since references accomplish some things that cannot be
accomplished otherwise, but even I missed the fact that the second loop was
using a variable that was a reference to the last element of the array as
created in the first loop *lol*. The user's very act of checking their results
was confounding the result... I love it :)

Cheers,
Rob.

Re, your "...that cannot be accomplished otherwise,..." Can you provide some
examples?  The only ones I've found are when using create_function() and the
arguments for callback functions. I can't even remember or find in my code an
example of my foreach()loops needed it. Seems, I recall earlier versions of PHP
[<4? ]required references for variables.

After I submitted "...that cannot be accomplished otherwise,...", I realized it was a patently false statement (a turing machine is a turing machine :). The intent of the statement though was to indicate the greater difficulty in achieving something relatively simple with references. See the other thread "Thinking out loud - continuation". My post dated 2012-03-24 00:24 shows a process that is cumbersome and inefficient to implement in another fashion. References are like pointers... very powerful but with cautions for the unwary.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux