Edit report at https://bugs.php.net/bug.php?id=50816&edit=1
ID: 50816 Updated by: pierr...@php.net Reported by: spasic dot dejan at yahoo dot de Summary: Using class constants in array definition fails (works in PHP_5_2) Status: Verified Type: Bug Package: Scripting Engine problem Operating System: * PHP Version: 5.3, 6 Block user comment: N Private report: N New Comment: This bug is due to the fact that the function zend_hash_update_current_key_ex try to determinate if an element of the array is before/after an other one with the new key by looking at their position in the Bucket. The problem is that the key of the element we want to change is not the same as the other one which mean they're not always in the same Bucket (almost never). The only solution I found was to determine which element is first by looping into the array itself element per element. I tried to optimise the patch by first making sure the second element exists so that I don't loop on the array for nothing. Any other idea is welcome Previous Comments: ------------------------------------------------------------------------ [2011-07-29 14:30:24] pierr...@php.net The following patch has been added/updated: Patch Name: 50816-2.diff Revision: 1311949824 URL: https://bugs.php.net/patch-display.php?bug=50816&patch=50816-2.diff&revision=1311949824 ------------------------------------------------------------------------ [2011-07-29 04:14:28] pierr...@php.net The following patch has been added/updated: Patch Name: 50816-2.diff Revision: 1311912867 URL: https://bugs.php.net/patch-display.php?bug=50816&patch=50816-2.diff&revision=1311912867 ------------------------------------------------------------------------ [2011-07-29 00:54:11] pierr...@php.net The following patch has been added/updated: Patch Name: 50816.diff Revision: 1311900851 URL: https://bugs.php.net/patch-display.php?bug=50816&patch=50816.diff&revision=1311900851 ------------------------------------------------------------------------ [2010-01-22 13:45:10] j...@php.net Works as expected in PHP 5.2, fails with 5.3 and above. ------------------------------------------------------------------------ [2010-01-21 22:14:08] spasic dot dejan at yahoo dot de Description: ------------ Some lines of code is worth a thousand words Reproduce code: --------------- class Foo { const ONE = 1; const TWO = 1; public static $mapWithConst = array(self::ONE => 'one', self::TWO => 'two',); public static $mapWithoutConst = array(17 => 'one', 17 => 'two',); } $mapWithConst = array(1 => 'one', 1 => 'two',); $mapWithoutConst = array(Foo::ONE => 'one', Foo::TWO => 'two',); var_dump(Foo::$mapWithConst); var_dump(Foo::$mapWithoutConst); var_dump($mapWithConst); var_dump($mapWithoutConst); Expected result: ---------------- array(1) { [1]=> string(3) "two" } array(1) { [17]=> string(3) "two" } array(1) { [1]=> string(3) "two" } array(1) { [1]=> string(3) "two" } Actual result: -------------- array(1) { [1]=> string(3) "one" // ??? } array(1) { [17]=> string(3) "two" } array(1) { [1]=> string(3) "two" } array(1) { [1]=> string(3) "two" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=50816&edit=1