|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22201 Array keys like "-123" are not turned into ints
Submitted: 2003-02-13 05:26 UTC Modified: 2003-02-13 06:53 UTC
From: carl at thep dot lu dot se Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.0 OS: SuSE 7.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
39 - 15 = ?
Subscribe to this entry?

 [2003-02-13 05:26 UTC] carl at thep dot lu dot se
A string which would evaluate to a negative integer (such as "-123")
will not be turned into an integer when used as an array key. I don't
recall seeing anywhere an explicit explanation of how strings are
treated when used as array keys, but obviously those strings that
are valid representations of non-negative integers are implicitly
treated as integers, and everything else is seen as strings.
I think it would make sense to extend this to _all_ valid integers, as
the behavior in this example is not quite what one would expect:

$arr = array(-1 => "a", 0 => "b", 1 => "c");
$arr["-1"] = "e";
$arr["0"] = "f";
$arr["1"] = "g";
echo "\n";


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-13 06:53 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

dupe of bug #21918
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 17:03:35 2021 UTC