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

From: Date: Fri, 01 Nov 2013 00:53:11 +0000
Subject: Bug #66015 [NEW]: Unexpected array indexing in class's static property
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182534@lists.php.net to get a copy of this message
From: jmcustiel at gmail dot com Operating system: Windows 7 PHP version: 5.4.21 Package: *General Issues Bug Type: Bug Bug description:Unexpected array indexing in class's static property 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 bug report at https://bugs.php.net/bug.php?id=66015&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66015&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66015&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66015&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66015&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66015&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66015&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66015&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66015&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66015&r=support Expected behavior: https://bugs.php.net/fix.php?id=66015&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66015&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66015&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66015&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66015&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66015&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66015&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66015&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66015&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66015&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66015&r=mysqlcfg

« previous php.bugs (#182534) next »