|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51384 Allow array keys "0", "1", etc.
Submitted: 2010-03-24 23:34 UTC Modified: 2010-04-30 00:52 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: info at fedushin dot ru Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.2 OS:
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.
Block user comment
Status: Assign to:
Bug Type:
From: info at fedushin dot ru
New email:
PHP Version: OS:


 [2010-03-24 23:34 UTC] info at fedushin dot ru
PHP Manual says about arrays: "A key may be either an integer or a string .".
But which strings can be used as key?
Even rather experienced programmer will answer: any, and will be wrong.
In fact, there's no way to use string keys "0", "1", etc. because they are implicitly converted into integer keys.
So, PHP engine's behaviour in this case should be considered as unpredictable.
This problem is rejected in Bug #9307, sorry for repetition.

Then, let's ask our experienced programmer what output will be generated by the following script:
// Assume we have already made successful mysql_connect().
$res = mysql_query('SELECT 1, "aaa";');
$row = mysql_fetch_array($res);
echo $row[0] . '<br>';
echo $row[1] . '<br>';
I think very few people will give correct answer:
So again we have unpredictable behaviour.

Suggestion is to improve this situation:
1. Allow storing values in PHP arrays under string keys .., "-1", "0", "1", ...
2. Always use strings & never use integers as associative indices in arrays returned by mysql_fetch_array().

Test script:
$a       = array();
$a[1]    = 'aaa';
$a['1']  = 'bbb';

$res 	= mysql_query('SELECT 1, "aaa";');
$row 	= mysql_fetch_array($res);

Expected result:
  1 => string 'bbb' (length=3)
  '1' => string 'bbb' (length=3)

  0 => string '1' (length=1)
  '1' => string '1' (length=1)
  1 => string 'aaa' (length=3)
  'aaa' => string 'aaa' (length=3)

Actual result:
  1 => string 'bbb' (length=3)

  0 => string '1' (length=1)
  1 => string '1' (length=1)
  2 => string 'aaa' (length=3)
  'aaa' => string 'aaa' (length=3)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-30 00:52 UTC]
-Status: Open +Status: Bogus
 [2010-04-30 00:52 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

See bug #45959
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Oct 02 17:05:52 2022 UTC