PHP 5.3 - Changes to array() definitions.

by justin carlson on 07/08/2009
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
)

Trackback

Trackback URL for this entry: http://www.tehuber.com/trackback.php?id=20090708165752413

No trackback comments for this entry.
PHP 5.3 - Changes to array() definitions. | 0 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.