|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-11-27 12:43 UTC] jmcustiel at gmail dot com
-Operating System: Windows 7
+Operating System: Win 7/Mac OS/Gnu-Linux(Ubuntu)
[2013-11-27 12:43 UTC] jmcustiel at gmail dot com
[2013-11-27 12:55 UTC] jmcustiel at gmail dot com
-Package: *General Issues
+Package: Arrays related
[2013-11-27 12:55 UTC] jmcustiel at gmail dot com
[2013-11-28 10:28 UTC] laruence@php.net
[2014-04-10 21:31 UTC] bwoebi@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: bwoebi
[2014-04-11 08:09 UTC] bwoebi@php.net
[2014-04-11 08:09 UTC] bwoebi@php.net
-Status: Assigned
+Status: Closed
[2014-04-11 08:12 UTC] bwoebi@php.net
[2014-04-15 12:04 UTC] ab@php.net
[2014-04-15 13:05 UTC] ab@php.net
[2014-05-01 14:59 UTC] tyrael@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 04:00:01 2025 UTC |
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', )