|  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
 [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-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 03:01:28 2024 UTC