Edit report at https://bugs.php.net/bug.php?id=21918&edit=1
ID: 21918 Comment by: sushant dot d84 at gmail dot com Reported by: messju at lammfellpuschen dot de Summary: strange behaviour of mixed type in array-keys Status: Closed Type: Bug Package: Scripting Engine problem Operating System: * PHP Version: 4.3.3-RC3/5.0.0b2 Assigned To: zeev Block user comment: N Private report: N New Comment: I have an array which I use for long Binary Tree. I am pasting the array here which shows the negative key. The code was very general $i=0; while ($MyCondition) { $i=$i*2+1; temparray[$i]= $MyItem; $i=$i*2+2; temparray[$i]= $MyItem; } and the output has one negative key in it.. " [-2147483648] => " Previous Comments: ------------------------------------------------------------------------ [2003-08-13 13:44:09] he...@php.net Well i didn't mean to shout or something like that :-) I reopened the bug because the part of the fix removed was for documentation consistency. And i didn't want to open a new bug on this. To be precise: "A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08"). There are no different indexed and associative array types in PHP; there is only one array type, which can both contain integer and string indices." (1) The above is the exact purpose of this bug and is fixed now. The inconsistency lies in this: "If you do not specify a key for a given value, then the maximum of the integer indices is taken, and the new key will be that maximum value + 1. If you specify a key that already has a value assigned to it, that value will be overwritten." (2) While the documentation says: "As of PHP 4.3.0, the index generation behaviour described above has changed. Now, if you append to an array in which the current maximum key is negative, then the next key created will be zero (0). Before, the new index would have been set to the largest existing key + 1, the same as positive indices are." (3) Since (1) and (2) were broken in PHP 4.3 i didn't really care about the note (3). If we leave the things as they are now (1) throughtout (3) match. However i like the behavior without (3) more since it is consistent and more logically. ------------------------------------------------------------------------ [2003-08-13 04:18:46] sni...@php.net Zeev is right about this being the wrong bug reopened, this is (still) fixed in CVS. ------------------------------------------------------------------------ [2003-08-13 02:55:03] z...@php.net It's not 'broken' again, what I reverted had nothing to do with this bug. Look at the diff before you start shouting! I'm still not sure if we'll keep the auto conversion for negative numbers. My preference is to fix the docs, since all sorts of other notations don't work, and we have no intention on making them work (e.g., $foo["+7"], $foo["3.5"], etc. ------------------------------------------------------------------------ [2003-08-12 18:45:55] sni...@php.net Zeev could at least explain WHY he reverted the fix.. ------------------------------------------------------------------------ [2003-08-12 15:46:46] he...@php.net Broken again ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=21918 -- Edit this bug report at https://bugs.php.net/bug.php?id=21918&edit=1