PHP 4.0 Bug #6117: next() fails when it reaches a "0" key

From: Date: Sat, 12 Aug 2000 06:20:58 +0000
Subject: PHP 4.0 Bug #6117: next() fails when it reaches a "0" key
Groups: php.dev 
Request: Send a blank email to php-dev+get-28634@lists.php.net to get a copy of this message
From: ronen@greyzone.com Operating system: Redhat Linux 6.2 PHP version: 4.0.1pl2 PHP Bug Type: Misbehaving function Bug description: next() fails when it reaches a "0" key When I use a for construct to step through an associative array, next() will stop when it reaches a key equivalent to "0". "0" is treated like the end of the array, even if it is not. SAMPLE CODE: <? $test[123]="one hundred twenty three"; $test[13]="thirteen"; $test[0]="zero"; $test[3]="three"; $test[11]="eleven"; // try the for construct: for(reset($test);$key=key($test);next($test)) { echo "TEST[$key]=".$test[$key]."<br>"; } echo "************************************<br>"; // try the foreach construct foreach($test as $key => $value) { echo "TEST[$key]=$value<br>"; } /***** THE OUTPUT IS: TEST[123]=one hundred twenty three TEST[13]=thirteen ************************************ TEST[123]=one hundred twenty three TEST[13]=thirteen TEST[0]=zero TEST[3]=three TEST[11]=eleven ****/ ?> Why does for not work, when foreach does? Ronen.

« previous php.dev (#28634) next »