|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-08 22:15 UTC] justin dot carlson at gmail dot com
Description:
------------
Array items are not as defined when using the same key twice.
I have not yet tested this outside of a class.
Reproduce code:
---------------
<?php
Foo::Bar();
abstract class Foo {
const A = 1;
const B = 2;
const C = 3;
const D = 1;
protected static $sample = array(
self::A => 'Apple',
self::B => 'Boy',
self::C => 'Cat',
self::D => 'Dog'
);
public static function Bar() {
print_R( self::$sample );
}
}
?>
Expected result:
----------------
In PHP 5.2.x:
Array
(
[2] => Boy
[3] => Cat
[1] => Dog
)
This is what I would expect to be valid, as the 2nd entry would override the first, making "Dog" the correct value for index 1.
Actual result:
--------------
In PHP 5.3.x:
Array
(
[1] => Apple
[2] => Boy
[3] => Cat
)
This was not expected, as the 1st entry maintained it's value.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
Thank you for your bug report. I was able to reproduce the problem and make the testcase somewhat simpler: <?php class Foo { const A = 1; const D = 1; public static $sample = array( self::A => 'First', self::D => 'Last' ); } print_r(Foo::$sample); ?>I've confirmed this in Linux as well. The following works fine: <?php define('a',1); define('b',1); $test = array(a => 'foo', b => 'bar'); print_R($test); ?> So, it may be related to class constants?