PHP 5.3 - Changes to array() definitions.

Wednesday, July 08 2009 @ 04:57 CDT

Contributed by: justin carlson

I've come accross this change ( bug? ) in PHP 5.3, while troubleshooting a Creole/Propel problem it caused.

Array items are not as defined when using the same key twice. PHP 5.3. Array order is Incorrect.
I have a feeling this will break code in other projects as well, so I've reported it here:
http://bugs.php.net/bug.php?id=48858&thanks=4


Code to reproduce:


<?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:

Array
(
    [2] => Boy
    [3] => Cat
    [1] => Dog
)

Actual result:

Array
(
    [1] => Apple
    [2] => Boy
    [3] => Cat
)

Comments (0)


tehuber.com
http://www.tehuber.com/article.php?story=20090708165752413