#29008 [Opn->Csd]: array_combine skips keys of type other than int or string
| From: | iliaa@php.net | Date: | Sun, 11 Jul 2004 15:24:04 +0000 |
| Subject: | #29008 [Opn->Csd]: array_combine skips keys of type other than int or string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-62022@lists.php.net to get a copy of this message | ||
ID: 29008
Updated by: iliaa@php.net
Reported By: tomas_matousek at hotmail dot com
-Status: Open
+Status: Closed
Bug Type: Arrays related
Operating System: WinXP
PHP Version: 5.0.0RC3
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2004-07-04 10:19:13] tomas_matousek at hotmail dot com
Description:
------------
The array_combine function skips keys of type other than int or string
while operator [] allows one to add also other types (like
null,boolean, float). Note, that array_combine converts string keys in
exactly the same way as the operator [] does (i.e. "10" -> 10 etc.).
IMHO array_combine should not skip keys with other types than string or
int but convert them to a string or an int.
Thus array_combine should behave like [] operator.
Moreover, the PHP_Compat package does it so but there is another bug
there: if illegal key is found (e.g. an array) a warning is reported
instead of skipping such key (@ is missing there).
Reproduce code:
---------------
$a = array("0",0,"-10",-10,null,5.4,array(1,2,3),false);
$b = array(1,2,3,4,5,6,7,8);
var_dump(array_combine($a,$b));
Expected result:
----------------
array(4) {
[0]=>
int(8)
[-10]=>
int(4)
[""]=>
int(5)
[5]=>
int(6)
}
Actual result:
--------------
array(2) {
[0]=>
int(2)
[-10]=>
int(4)
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29008&edit=1