php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21954 array_key_exists warns for large numeric keys
Submitted: 2003-01-29 16:40 UTC Modified: 2003-01-30 03:46 UTC
From: elnormo at hotmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.0 OS: RedHat Linux
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: elnormo at hotmail dot com
New email:
PHP Version: OS:

 

 [2003-01-29 16:40 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-30 03:46 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
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC