Edit report at https://bugs.php.net/bug.php?id=60039&edit=1

 ID:                 60039
 Updated by:         cataphr...@php.net
 Reported by:        ni...@php.net
 Summary:            array_key_exists behaves different from isset for
                     float keys
 Status:             Open
-Type:               Bug
+Type:               Feature/Change Request
 Package:            Arrays related
 PHP Version:        5.4.0beta1
 Block user comment: N
 Private report:     N

 New Comment:

It's very arguable whether the behavior of the two should match.

A argument for the current behavior would go like this: in $a = [4 => "hhh"], 
the key 4.5 doesn't exist, so key_exists should return false; on the other hand 
$a[4.5] exists and is not null, so isset should return true. There are some 
problems with this argument, namely that key_exists actually rejects the 
arguments (it sends a warning) and that there is a very slight mismatch between 
isset and array dereferencing, but it's just to show this is not a bug 
(violation of well established specifications), but instead a feature request 
that merits more discussion.


Previous Comments:
------------------------------------------------------------------------
[2011-10-11 12:19:09] ni...@php.net

The following patch has been added/updated:

Patch Name: array_key_exists_patch.txt
Revision:   1318335549
URL:        
https://bugs.php.net/patch-display.php?bug=60039&patch=array_key_exists_patch.txt&revision=1318335549

------------------------------------------------------------------------
[2011-10-11 12:18:40] ni...@php.net

Description:
------------
array_key_exists allows only string, int and null keys. For everything else 
it'll throw an error.
isset on the other hand allows floats, resources and bools too. floats are cast 
to int and resources and bools are handled as ints.

array_key_exists behavior should match isset behavior.



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60039&edit=1

Reply via email to