#45100 [Opn]: array_key_exists() doesn't accept the same key as real array

From: Date: Tue, 27 May 2008 15:59:23 +0000
Subject: #45100 [Opn]: array_key_exists() doesn't accept the same key as real array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125306@lists.php.net to get a copy of this message
ID: 45100 Updated by: colder@php.net Reported By: atom at atomsoft dot cz Status: Open Bug Type: *General Issues Operating System: Windows XP PHP Version: 5.2.6 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2008-05-27 04:36:01] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45100&edit=1

« previous php.bugs (#125306) next »