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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 14:01:31 2024 UTC