php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44825 array_key_exists() The first argument should be either a string or an integer
Submitted: 2008-04-24 21:41 UTC Modified: 2008-04-24 22:11 UTC
From: dmitrij at stepanov dot lv Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.5 OS: Windows XP
Private report: No CVE-ID: None
 [2008-04-24 21:41 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-24 21:45 UTC] 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 22:11 UTC] dmitrij at stepanov dot lv
OMG.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 16:01:29 2024 UTC