Bug #13741 Updated: Cannot walk the same associative array twice in the same script

From: Date: Fri, 19 Oct 2001 10:38:33 +0000
Subject: Bug #13741 Updated: Cannot walk the same associative array twice in the same script
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-68328@lists.php.net to get a copy of this message
ID: 13741
Updated by: hholzgra
Reported By: milo@cyberlifelabs.com
Status: Bogus
Bug Type: Arrays related
Operating System: FreeBSD 4.2-RELEASE
PHP Version: 4.0.6
New Comment:

... or read the documentation on each() itself:

"[...]
After each() has executed, the array cursor will be left on the next element of the array, or on the
last element if it hits the end of the array
[...]"


Previous Comments:
------------------------------------------------------------------------

[2001-10-19 06:35:15] hholzgra@php.net

see http://php.net/reset

------------------------------------------------------------------------

[2001-10-19 06:19:43] milo@cyberlifelabs.com

I have a simple associative array of scalar name/value 
pairs -- specifically, the 50 US states and their 
abbreviations. The array is sorted using asort().

Two places in my script, I walk the array using the 
list/each syntax:

	while(list($abbr,$name) = each($STATES_HASH))
	{
		...
	}

The first time, everything works as it should. All 
subsequent times however (within the same script) the 
array acts as though it's blank. If I query the size using 
sizeof(), it reports the correct value. If I try to 
extract values from the array, it works fine. If I make a 
copy of the array to a new variable, the copy works 
properly (the first time).

It seems like there's a bug in the each() function. Looks 
almost as if every associative array has a pointer to the 
current element that's not getting reset when each() is 
done with it.

My configure line is as follows:

 './configure' '--prefix=/usr/local/php-4.0.6' 
'--with-apache=../apache_1.3.19' 
'--with-pgsql=/usr/local/pgsql' '--enable-track-vars' 
'--with-config-file-path=/etc' 
'--with-jpeg-dir=/usr/local' '--with-tiff-dir=/usr/local' 
'--with-png-dir=/usr/local' '--with-zlib-dir=/usr/local' 
'--with-pdflib=/usr/local'



------------------------------------------------------------------------



Edit this bug report at http://bugs.php.net/?id=13741&edit=1



Thread (4 messages)

« previous php.dev (#68328) next »