|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-08-01 14:24 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 21:00:01 2025 UTC |
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 )