Re: PHP 4.0 Bug #5270: Nested foreach() using a copy of the same array does not work properly.

From: Date: Wed, 28 Jun 2000 21:10:00 +0000
Subject: Re: PHP 4.0 Bug #5270: Nested foreach() using a copy of the same array does not work properly.
References: 1 2 3  Groups: php.dev 
Request: Send a blank email to php-dev+get-22673@lists.php.net to get a copy of this message
On Wed, 28 Jun 2000, Daniel Beckham wrote: > Well, seeing as how php's array usage is a bit screwy (relative to my > opinion of how it should work), that does make sense. The second foreach() > statement is resetting the array pointer php uses for that array so that it > can loop through each element. Now, why that happens on a copy is a mystery. > > While I'm on that subject... Why is php a array pointer Nazi? It seems > that a pointer is assigned to an array at birth. From then on.. any > function that touches that array can possibly reset, move or otherwise > wreak havoc on that pointer. Wouldn't it make more sense to temporarily > assign a new pointer to the array in the context of the current loop it's > in? That way, you could nest any number of loops without fear you will > alter how the top loop works. > > By making sense, I mean from the php programmer's standpoint, not the > internals of how arrays work in the zend engine. Actually, recently there was some internal API functionality added that allows and array traversal command to not touch the internal array pointer. It would be possible to go through the code base and convert it to new functionality, but the question is whether that would be backward compatible. -Andrei * It's an emergent property of human minds to create. *

« previous php.dev (#22673) next »