php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34857 Change array_combine behaviour when called with empty arrays
Submitted: 2005-10-13 15:07 UTC Modified: 2010-08-27 05:54 UTC
Votes:15
Avg. Score:4.3 ± 0.7
Reproduced:14 of 14 (100.0%)
Same Version:3 (21.4%)
Same OS:5 (35.7%)
From: stochnagara at hotmail dot com Assigned: aharvey (profile)
Status: Closed Package: Arrays related
PHP Version: 5.1.0RC1 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: stochnagara at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-10-13 15:07 UTC] stochnagara at hotmail dot com
Description:
------------
Currently array_combine returns false and raises a warning if it is used with two empty array and this is documented too.
This is quite inconsistent since combining two empty arrays is expected to result in another empty array.
If there are so many BC arguments, then this function could be extended with a third optional argument 'accept_empty' which allow the thing I request.

P.S. Actually bug #29972 is almost the same and has been marked closed so this could be a reopen of this bug.

Reproduce code:
---------------
<?php
var_dump (array_combine (array(), array()));
?>


Expected result:
----------------
array(0) { }

Actual result:
--------------
Warning: array_combine() [function.array-combine]: Both parameters should have at least 1 element in C:\Program Files\Apache Group\Apache2\htdocs\boroinvest\test.php on line 3
bool(false) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-21 22:05 UTC] ms419 at freezone dot co dot uk
I am trying to parse the output of "svnlook proplist -v" into an associative array of property keys and property values:

            $pattern = '/^  ([^ ]+) : ((?:\V|\v[^ ]|\v [^ ])+)/m';
            if (false === preg_match_all($pattern, $subject, $matches)) {

                // Error handling
            }

            return array_combine($matches[1], $matches[2]);

This works great, unless "svnlook proplist -v" finds no properties. In that case, array_combine() returns false because array() === $matches[1] and array() === $matches[2].

Consequently, I am forced to treat the case when "svnlook proplist -v" finds no properties as a special case.

I wish array() === array_combine(array(), array()), as I assumed it would.
 [2010-08-26 18:13 UTC] joel dot perras+phpbugs at gmail dot com
Patch against the current svn HEAD of trunk available here: 
http://paste.roguecoders.com/p/16e1e953e8b1890bcaaba00eb8408dd7.txt
 [2010-08-27 05:43 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: aharvey
 [2010-08-27 05:44 UTC] aharvey@php.net
-Package: *General Issues +Package: Arrays related
 [2010-08-27 05:54 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=302838
Log: Implemented request #34857 (Change array_combine behaviour when called with
empty arrays). Patch by Joel Perras &lt;joel.perras@gmail.com&gt;.
 [2010-08-27 05:54 UTC] aharvey@php.net
-Summary: Change array_combine behavoiur +Summary: Change array_combine behaviour when called with empty arrays -Status: Assigned +Status: Closed
 [2010-08-27 05:54 UTC] aharvey@php.net
This bug has been fixed in SVN.

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.

Thanks very much for the patch, Joel.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 05 16:01:30 2024 UTC