php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40730 Array sequence corrupted when elements are added with double digit indexes
Submitted: 2007-03-05 14:55 UTC Modified: 2007-03-05 14:59 UTC
From: slawo_c at o2 dot pl Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.1 OS: Mac OS X 10.4.8
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: slawo_c at o2 dot pl
New email:
PHP Version: OS:

 

 [2007-03-05 14:55 UTC] slawo_c at o2 dot pl
Description:
------------
When I create an array using the following code the array is corrupted for some reason, as if the double digits were misinterpreted or misread at some point. From my experience it happens specifically on index 08 and 09 (which are set to 0) Even if the order is different.
The consequence is that data with index 08 will be overwritten by 09 or 09 will be overwritten by 08 if 08 is set after 09.

Example code:




Reproduce code:
---------------
$list = array();
$list[01]='a';
$list[02]='b';
$list[03]='c';
$list[04]='d';
$list[05]='da';
$list[06]='db';
$list[07]='dc';
$list[08]='e';
$list[09]='ea';
$list[10]='eb';
$list[11]='ec';
$list[12]='f';

echo '<pre>';
var_dump($list);
echo '</pre>';

Expected result:
----------------
array(11) {
  [1]=>
  string(1) "a"
  [2]=>
  string(1) "b"
  [3]=>
  string(1) "c"
  [4]=>
  string(1) "d"
  [5]=>
  string(2) "da"
  [6]=>
  string(2) "db"
  [7]=>
  string(2) "dc"
  [8]=>
  string(2) "e"
  [9]=>
  string(2) "ea"
  [10]=>
  string(2) "eb"
  [11]=>
  string(2) "ec"
  [12]=>
  string(1) "f"
  }

Actual result:
--------------
array(11) {
  [1]=>
  string(1) "a"
  [2]=>
  string(1) "b"
  [3]=>
  string(1) "c"
  [4]=>
  string(1) "d"
  [5]=>
  string(2) "da"
  [6]=>
  string(2) "db"
  [7]=>
  string(2) "dc"
  [0]=>
  string(2) "ea" //<- Here 09 overwrote 08 which was also set to 0 by the parser/interpreter?
  [10]=>
  string(2) "eb"
  [11]=>
  string(2) "ec"
  [12]=>
  string(1) "f"
  }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-05 14:59 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu May 28 07:01:25 2020 UTC