#44100 [Asn->Csd]: Inconsistent handling of static array declarations with duplicate keys

From: Date: Fri, 01 Aug 2008 14:24:03 +0000
Subject: #44100 [Asn->Csd]: Inconsistent handling of static array declarations with duplicate keys
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-127465@lists.php.net to get a copy of this message
ID: 44100 Updated by: dmitry@php.net Reported By: robin_fernandes at uk dot ibm dot com -Status: Assigned +Status: Closed Bug Type: Scripting Engine problem Operating System: Windows PHP Version: 5.2CVS-2008-02-11 (snap) Assigned To: dmitry New Comment: Fixed in CVS HEAD and PHP_5_3 (it won't be fixed in PHP_5_2). Previous Comments: ------------------------------------------------------------------------ [2008-02-11 17:38:46] robin_fernandes at uk dot ibm dot com 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 this bug report at http://bugs.php.net/?id=44100&edit=1

« previous php.bugs (#127465) next »