Bug #66015 [Opn]: Unexpected array indexing in class's static property

From: Date: Wed, 27 Nov 2013 12:43:02 +0000
Subject: Bug #66015 [Opn]: Unexpected array indexing in class's static property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182961@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 User updated by: jmcustiel at gmail dot com Reported by: jmcustiel at gmail dot com Summary: Unexpected array indexing in class's static property Status: Open Type: Bug Package: *General Issues -Operating System: Windows 7 +Operating System: Win 7/Mac OS/Gnu-Linux(Ubuntu) PHP Version: 5.4.21 Block user comment: N Private report: N New Comment: Reproduced the bug in MacOS and Ubuntu. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#182961) next »