#22201 [NEW]: Array keys like "-123" are not turned into ints

From: Date: Thu, 13 Feb 2003 11:26:09 +0000
Subject: #22201 [NEW]: Array keys like "-123" are not turned into ints
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-33003@lists.php.net to get a copy of this message
From:             carl@thep.lu.se
Operating system: SuSE 7.2
PHP version:      4.3.0
PHP Bug Type:     Arrays related
Bug description:  Array keys like "-123" are not turned into ints

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";
print_r($arr);
echo "\n";
var_dump($arr);

-- 
Edit bug report at http://bugs.php.net/?id=22201&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=22201&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=22201&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=22201&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=22201&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=22201&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=22201&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=22201&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=22201&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=22201&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=22201&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22201&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=22201&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=22201&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=22201&r=gnused



Thread (2 messages)

« previous php.bugs (#33003) next »