Bug #66015 [Asn->Csd]: Unexpected array indexing in class's static property
| From: | bwoebi@php.net | Date: | Fri, 11 Apr 2014 08:09:29 +0000 |
| Subject: | Bug #66015 [Asn->Csd]: Unexpected array indexing in class's static property | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185175@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66015&edit=1
ID: 66015
Updated by: bwoebi@php.net
Reported by: jmcustiel at gmail dot com
Summary: Unexpected array indexing in class's static property
-Status: Assigned
+Status: Closed
Type: Bug
Package: Arrays related
Operating System: Win 7/Mac OS/Gnu-Linux(Ubuntu)
PHP Version: 5.4.21
Assigned To: bwoebi
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f614fc68984b2d7fce3f275b8106955b5d910472
Log: Fix bug #66015 by reverting "Removed operations on constant arrays."
Previous Comments:
------------------------------------------------------------------------
[2013-11-28 10:28:17] laruence@php.net
actually, this is "kind of" not bug...
self::first will be expanded in runtime.
before that, the array is array(0 => 'second', 1 => 'third'
,'self::FIRST' => 'fist')
in runtime, when doing class static member constants expanding, then self::FIRST expanded to 0,
which will be failed since the 0 key is occupied..
------------------------------------------------------------------------
[2013-11-27 12:55:00] jmcustiel at gmail dot com
Changed the package field's value.
------------------------------------------------------------------------
[2013-11-27 12:43:02] jmcustiel at gmail dot com
Reproduced the bug in MacOS and Ubuntu.
------------------------------------------------------------------------
[2013-11-01 00:53:11] jmcustiel at gmail dot com
Description:
------------
I have a class with a static property of type array. This array starts with a key/value pair with a
numeric key (value 1 defined in a constant) used to start the indexing. After that, just another two
values, expecting the keys to be autogenerated after the initial index.
I expect the array keys to be correlative starting from 1, and to 3. But the array has only two keys
starting from 0, and to 1.
I attached a test script, for the script I expect the output to be:
array (
1 => 'first',
2 => 'second',
3 => 'third',
)
but, instead I get:
array (
0 => 'second',
1 => 'third',
)
I tested it using [] and array() and get the same results.
It only happens when using self:: followed by constant name as first key in the static property, the
next two code portions works as expected, both inside or outside of the class:
$arr = array(
1 => 'a',
'b',
'c'
);
$arr = array(
Test::FIRST => 'd',
'e',
'f'
);
Test script:
---------------
class Test
{
const FIRST = 1;
const SECOND = 2;
const THIRD = 3;
protected static $array = [
self::FIRST => 'first',
'second',
'third'
];
public function __construct()
{
var_export(self::$array);
}
}
$test = new Test();
Expected result:
----------------
array (
1 => 'first',
2 => 'second',
3 => 'third',
)
Actual result:
--------------
array (
0 => 'second',
1 => 'third',
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66015&edit=1