PHP 4.0 Bug #5822: key() skips the next key if element previously unset

From: Date: Thu, 27 Jul 2000 18:31:06 +0000
Subject: PHP 4.0 Bug #5822: key() skips the next key if element previously unset
Groups: php.dev 
Request: Send a blank email to php-dev+get-26549@lists.php.net to get a copy of this message
From: nathan@cjhunter.com Operating system: Linux 2.0.28 PHP version: 4.0.0 PHP Bug Type: Misbehaving function Bug description: key() skips the next key if element previously unset If php is looping through an assoc array using the key() function the next element after an element has been unset is then skipped. I think the problem is the array pointer is not being set appropriately after the unset. Here is below is an example of the behavior. $a = array("a" => 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5); reset($a); while($key = key($a)){ echo $key . "<br>\n"; if($a[$key] == 2){ unset($a[$key]); } next($a); } var_dump($a); /* This returns the below. Notice the "c" key is not given. a b d e array(4) { ["a"]=> int(1) ["c"]=> int(3) ["d"]=> int(4) ["e"]=> int(5) } */

« previous php.dev (#26549) next »