php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29008 array_combine skips keys of type other than int or string
Submitted: 2004-07-04 10:19 UTC Modified: 2004-07-11 17:24 UTC
From: tomas_matousek at hotmail dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.0.0RC3 OS: WinXP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tomas_matousek at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-07-04 10:19 UTC] 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)
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-11 17:24 UTC] iliaa@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC