php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28072 static array with some constant keys will be incorrectly ordered
Submitted: 2004-04-20 07:54 UTC Modified: 2005-07-07 17:27 UTC
From: pages at inrp dot fr Assigned: dmitry
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS, 4CVS (2005-06-19) OS: *
Private report: No CVE-ID:
 [2004-04-20 07:54 UTC] pages at inrp dot fr
Description:
------------
Initialising a static associative array using constants as keys will give an incorrectly ordered array. Apparently, elements with constant keys will always appear AFTER elements without constant keys.

Reproduce code:
---------------
<?php
define("FIRST_KEY", "a");
define("THIRD_KEY", "c");
                                                                                          
function test()
{
        static $arr = array(
                FIRST_KEY => "111",
                "b" => "222",
                THIRD_KEY => "333",
                "d" => "444"
        );
        print_r($arr);
}
                                                                                          
test();
?>


Expected result:
----------------
Array
(
    [a] => 111
    [b] => 222
    [c] => 333
    [d] => 444
)


Actual result:
--------------
Array
(
    [b] => 222
    [d] => 444
    [a] => 111
    [c] => 333
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-07 17:27 UTC] dmitry@php.net
Fixed in CVS HEAD.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 10:02:06 2014 UTC