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

From: Date: Thu, 24 Apr 2008 21:45:06 +0000
Subject: #44825 [Opn->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-124497@lists.php.net to get a copy of this message
ID: 44825 Updated by: felipe@php.net Reported By: dmitrij at stepanov dot lv -Status: Open +Status: Bogus -Bug Type: Unknown/Other Function +Bug Type: Arrays related Operating System: Windows XP PHP Version: 5.2.5 New Comment: 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" } Previous Comments: ------------------------------------------------------------------------ [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 (#124497) next »