#44825 [Bgs]: array_key_exists() The first argument should be either a string or an integer

From: Date: Thu, 24 Apr 2008 22:11:21 +0000
Subject: #44825 [Bgs]: array_key_exists() The first argument should be either a string or an integer
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-124500@lists.php.net to get a copy of this message
ID: 44825 User updated by: dmitrij at stepanov dot lv Reported By: dmitrij at stepanov dot lv Status: Bogus Bug Type: Arrays related Operating System: Windows XP PHP Version: 5.2.5 New Comment: OMG. Previous Comments: ------------------------------------------------------------------------ [2008-04-24 21:45:06] felipe@php.net Negative! Says the documentation: "A key may be either an integer or a string... Floats in key are truncated to integer." $ php -r '$a[2.3] = "foo"; var_dump($a);' array(1) { [2]=> string(3) "foo" } ------------------------------------------------------------------------ [2008-04-24 21:41:58] dmitrij at stepanov dot lv Description: ------------ array_key_exists() does not accept float as a key. (The first argument should be either a string or an integer), however it is possible to use floats as keys. Reproduce code: --------------- $array =array( 3.15 =>20); var_dump( array_key_exists( 3.15, $array)) ."\n";// ERROR: The first argument should be either a string or an integer echo $array[3.15];//OK Expected result: ---------------- boolean(true) 20 Actual result: -------------- blahblahblah 20 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44825&edit=1

« previous php.bugs (#124500) next »