From: robin_fernandes at uk dot ibm dot com Operating system: Windows PHP version: 5.2CVS-2008-02-11 (snap) PHP Bug Type: Scripting Engine problem Bug description: Inconsistent handling of static array declarations with duplicate keys
Description: ------------ There is an inconsistency when handling array declarations that include multiple entries with the same key but different values, such as array('a'=>0, 'a'=>1). In almost all cases, the last value will be used (1 in the example above). But the last part of the testcase below shows an inconsistent case, where the array is a static variable AND the first duplicate key is a constant rather than a literal. This is because in zval_update_constant_ex(), array entries with keys marked IS_CONSTANT_INDEX are always updated, regardless of the presence and position of other elements with the same key. Reproduce code: --------------- <?php echo "Duplicate key in non static array declaration:\n"; $nonStatic1 = array('a'=>0, 'a'=>1); print_r($nonStatic1); // [a] => 1 --> OK echo "\nDuplicate key in static array declaration:\n"; static $static1 = array('a'=>0, 'a'=>1); print_r($static1); // [a] => 1 --> OK define('DUP_KEY', 'a'); echo "\nDuplicate key in non static array declaration using constant as first key:\n"; $nonStatic2 = array(DUP_KEY=>0, 'a'=>1); print_r($nonStatic2); // [a] => 1 --> OK echo "\nDuplicate key in static array declaration using constant as first key:\n"; static $static2 = array(DUP_KEY=>0, 'a'=>1); print_r($static2); // [a] => 0 --> bug? ?> Expected result: ---------------- Duplicate key in non static array declaration: Array ( [a] => 1 ) Duplicate key in static array declaration: Array ( [a] => 1 ) Duplicate key in non static array declaration using constant as first key: Array ( [a] => 1 ) Duplicate key in static array declaration using constant as first key: Array ( [a] => 1 ) Actual result: -------------- Duplicate key in non static array declaration: Array ( [a] => 1 ) Duplicate key in static array declaration: Array ( [a] => 1 ) Duplicate key in non static array declaration using constant as first key: Array ( [a] => 1 ) Duplicate key in static array declaration using constant as first key: Array ( [a] => 0 ) -- Edit bug report at http://bugs.php.net/?id=44100&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=44100&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44100&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44100&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44100&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44100&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44100&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44100&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44100&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44100&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44100&r=support Expected behavior: http://bugs.php.net/fix.php?id=44100&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44100&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44100&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44100&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=44100&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=44100&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44100&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44100&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44100&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44100&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44100&r=mysqlcfg