php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45100 array_key_exists() doesn't accept the same key as real array
Submitted: 2008-05-27 04:36 UTC Modified: 2008-07-15 01:29 UTC
From: atom at atomsoft dot cz Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.6 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: atom at atomsoft dot cz
New email:
PHP Version: OS:

 

 [2008-05-27 04:36 UTC] atom at atomsoft dot cz
Description:
------------
floor() return double type, but in documentation is floor.
This is first bug. But for it exist another bug report.

Second problem is array_key_exists() it hasn't accepted by array_key_exists, but $a[$key] = 'value' is OK. I think, that PHP accept double a key index, array_key_exists should be accept it too.

Reproduce code:
---------------
$key = floor(1/10);
$a = array();
$a[$key] = 'value';
echo $a[$key] . "\n";
echo array_key_exists($key, $a)? "YES\n" : "NO\n";
echo gettype($key) . "\n";  

Expected result:
----------------
value
YES
float (according documentation)

Actual result:
--------------
value
Warning:  array_key_exists() function.array-key-exists: The first argument should be either a string or an integer in ...
NO
double

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-27 15:59 UTC] colder@php.net
http://php.net/types.float : "double" is similar to "float"
http://php.net/types.array : "key may only be an integer or string"

Your double/float key will be automatically translated to an int. So when you do $array[0.1] = 2;, $array[0] will be defined. 

For array_key_exists(), this conversion is not done automatically.
http://php.net/array_key_exists : "key can be any value possible for an array index" and a float is not a possible value for an array index, hence the error.

Maybe that conversion should be automatically done in array_key_exists though.
 [2008-07-15 01:29 UTC] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Feb 07 04:00:01 2026 UTC