You are here: Re: Finite $_POST loops infinitely - help! « PHP Programming Language « IT news, forums, messages
Re: Finite $_POST loops infinitely - help!

Posted by Andrew Poelstra on 08/22/06 21:37

"comp.lang.php" <phillip.s.powell@gmail.com> writes:
> Well, this is what I found out:
>
> No matter what I put within the foreach loop, the loop ran infinitely,
> and this is why:
>
> It constantly read $key as the very first element in $array, in short,
> it never iterated in the first place!
>
> This only happens when I do this;
>
> function doStuff(&$array) {
> if (is_array($array) && @sizeof($array) > 0) {
> foreach ($array as $key => $val) print_r("key = $key<P>"); //
> PRINTS "key = username" infinitely
> }
> }
>
>
> What I suspect at this point that this is a PHP 4.3+ bug. I had
> someone else in my DC PHP group test in PHP 5 and the loop iterated
> just fine.
>

That's what it looks like. If it's not a bug, then by definition it's a
documented "feature" in PHP 4.3x, and it'll be somewhere on the site.

One of the many unfortunate aspects of a bug is that the group can't
help you, other than to suggest you upgrade your version of PHP.

> If I pass the array not-by-reference in PHP 4.3.9, it iterates just
> fine:

Another phrase for "not-by-reference" is "by value", FYI.

>
> function doStuff($array) {
> if (is_array($array) && @sizeof($array) > 0) {
> foreach ($array as $key => $val) print_r("key = $key<P>"); // PRINTS
> "key = username" 5 times and stops
> }
> }
>

Instead of passing by reference, you could pass by value and then return
the modified version. That appears to be the best solution unless you have
the power to install PHP5.

--
Andrew Poelstra <http://www.wpsoftware.net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация