php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9307 Numeric-looking array keys are forced to be integers
Submitted: 2001-02-16 16:17 UTC Modified: 2001-03-06 08:24 UTC
From: david@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: Linux
Private report: No CVE-ID: None
 [2001-02-16 16:17 UTC] david@php.net
<?
$myarray['105'] = 'Hello';
$myarray[(string)'106'] = 'Goodbye';
var_dump($myarray);
?>

array(2) {
  [105]=>
  string(5) "Hello"
  [106]=>
  string(7) "Goodbye"
}

It shouldn't be auto-converting array keys to numbers if they're already of a different type! Let's say I have an whole list of items as my array keys, and one just happens to be "able" to be converted into a number. Suddenly one of my array keys is no longer a string.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-06 08:24 UTC] stas@php.net
Right, this is how PHP works. That's not a bug, that's an
intended behaviour.
 [2010-03-31 12:22 UTC] info at fedushin dot ru
Some arguments to consider (integer)1 and "1" as different array keys are given in Bug #51384.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 09:01:29 2024 UTC