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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dmitrij at stepanov dot lv
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 10:01:33 2025 UTC