Odd behavior with unset, array indexes, and types

From: Date: Thu, 17 Jun 2004 21:52:32 +0000
Subject: Odd behavior with unset, array indexes, and types
Groups: php.general 
Request: Send a blank email to php-general+get-188512@lists.php.net to get a copy of this message
Just noticed this today. The following script: <quote> $a = 2; $b = ceil(3 / 2); if ($a == $b) { print "\$a and \$b are the same.\n"; } $foo[$a] = '2'; if (isset($foo[$b])) { print "\$foo[\$b] is set.\n"; } unset($foo[$b]); print_r($foo); </quote> Results in this output: <quote> $a and $b are the same. $foo[$b] is set. Array ( [2] => 2 ) </quote> ceil() returns a variable of type double. In the above script I expected $foo to become an empty array after calling unset(). But it seems that unset() will not remove an array element when you refer to its key using a double, although isset() will return true when referenced the same way. If I cast $b to either an int or a string, the unset call works. Am I just missing the portion of the manual that documents this behavior, or is this a bug? Just thought I'd see if anyone had run across this before...TIA

« previous php.general (#188512) next »