ID: 44100
Updated by: [EMAIL PROTECTED]
Reported By: robin_fernandes at uk dot ibm dot com
-Status: Open
+Status: Assigned
Bug Type: Scripting Engine problem
Operating System: Windows
PHP Version: 5.2CVS-2008-02-11 (snap)
-Assigned To:
+Assigned To: dmitry
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