Bug #69125 [Opn->Csd]: Array numeric string as key
| From: | laruence@php.net | Date: | Fri, 27 Feb 2015 03:44:17 +0000 |
| Subject: | Bug #69125 [Opn->Csd]: Array numeric string as key | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-190976@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69125&edit=1
ID: 69125
Updated by: laruence@php.net
Reported by: dm@php.net
Summary: Array numeric string as key
-Status: Open
+Status: Closed
Type: Bug
Package: opcache
Operating System: Ubuntu 14.04
PHP Version: 5.6.6
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3e82816ba1a82843a352ce4050b2010fd9932dee
Log: Fixed bug #69125 (Array numeric string as key)
Previous Comments:
------------------------------------------------------------------------
[2015-02-27 01:37:38] edgar dot r dot sandi at gmail dot com
Hi!
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:
bool(true)
bool(true)
bool(true)
cheers
Edgar R. Sandi
------------------------------------------------------------------------
[2015-02-26 13:37:26] dm@php.net
var_dump(isset($array[SZERO]), isset($array['0']), isset($array[0])); returns
false for every expression.
------------------------------------------------------------------------
[2015-02-26 13:25:59] dm@php.net
Wrong package.
------------------------------------------------------------------------
[2015-02-26 13:23:08] dm@php.net
Description:
------------
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:
---------------
<?php
const SZERO = '0';
$array[SZERO] = PHP_VERSION;
var_dump($array);
Expected result:
----------------
array (size=1)
0 => string '5.6.6-1+deb.sury.org~trusty+1' (length=29)
Actual result:
--------------
array (size=1)
'0' => string '5.6.6-1+deb.sury.org~trusty+1' (length=29)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69125&edit=1