|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69125 Array numeric string as key
Submitted: 2015-02-26 13:23 UTC Modified: 2015-02-26 13:37 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: Assigned:
Status: Closed Package: opcache
PHP Version: 5.6.6 OS: Ubuntu 14.04
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:
40 - 26 = ?
Subscribe to this entry?

 [2015-02-26 13:23 UTC]
Numeric string as array key is allowed (not cast to int) if the key value is passed as constant (or possibly some other way too).
This can be achieved by casting object with numeric properties to array, but normally one cannot assign numeric string as array key.

Also, `isset($array['0'])` returns `false` even tho it exists. (possibly another bug or a feature?)

Test script:

const SZERO = '0';



Expected result:
array (size=1)
  0 => string '' (length=29)

Actual result:
array (size=1)
  '0' => string '' (length=29)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-26 13:25 UTC]
-Package: optimizer +Package: opcache
 [2015-02-26 13:25 UTC]
Wrong package.
 [2015-02-26 13:37 UTC]
`var_dump(isset($array[SZERO]), isset($array['0']), isset($array[0]));` returns `false` for every expression.
 [2015-02-27 01:37 UTC] edgar dot r dot sandi at gmail dot com

maybe that's not a bug, i think that the error is in the attribution of constant.

If you use:
const SZERO = 0; // as int instead string

Then the outputs of:
var_dump(isset($array[SZERO]), isset($array['0']), isset($array[0]));

Will be:

Edgar R. Sandi
 [2015-02-27 03:44 UTC]
Automatic comment on behalf of laruence
Log: Fixed bug #69125 (Array numeric string as key)
 [2015-02-27 03:44 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Sep 30 06:05:54 2022 UTC