#21954 [Opn->Bgs]: array_key_exists warns for large numeric keys

From: Date: Thu, 30 Jan 2003 09:46:46 +0000
Subject: #21954 [Opn->Bgs]: array_key_exists warns for large numeric keys
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-31670@lists.php.net to get a copy of this message
 ID:               21954
 Updated by:       derick@php.net
 Reported By:      elnormo@hotmail.com
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: RedHat Linux
 PHP Version:      4.3.0
 New Comment:

This is not a bug, the number you are using is NOT an integer because
it's larger then 2^31-1 (the maximum integer value in PHP) and thus it
will be converted to a float. Use
 
$a[(string)2163195907] = "hi";
echo array_key_exists((string)2163195907,$a);

and it should work fine.

Derick


Previous Comments:
------------------------------------------------------------------------

[2003-01-29 16:40:18] elnormo@hotmail.com

Try this script:

<?php
	$a = array();
	$a[2163195907] = "hi";
	echo array_key_exists(2163195907,$a);
?>

PHP generates a warning (The first argument should be either a string
or an integer). If I try this with smaller integers, the code works
fine. If I convert the integer to a string (using strval), it also
works fine.

Norman Elton

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


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



Thread (2 messages)

« previous php.bugs (#31670) next »