PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #21954 array_key_exists warns for large numeric keys
Submitted:29 Jan 2003 4:40pm UTC Modified: 30 Jan 2003 3:46am UTC
From:elnormo at hotmail dot com Assigned to:
Status:Bogus Category:Arrays related
Version:4.3.0 OS:RedHat Linux
View/Vote Developer Edit Submission

[29 Jan 2003 4:40pm UTC] elnormo at hotmail dot 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
[30 Jan 2003 3:46am UTC] derick@php.net
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

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC