Edit report at http://bugs.php.net/bug.php?id=34857&edit=1
ID: 34857 Updated by: ahar...@php.net Reported by: stochnagara at hotmail dot com -Summary: Change array_combine behavoiur +Summary: Change array_combine behaviour when called with empty arrays -Status: Assigned +Status: Closed Type: Feature/Change Request Package: Arrays related PHP Version: 5.1.0RC1 Assigned To: aharvey Block user comment: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2010-08-27 05:54:12] ahar...@php.net Automatic comment from SVN on behalf of aharvey Revision: http://svn.php.net/viewvc/?view=revision&revision=302838 Log: Implemented request #34857 (Change array_combine behaviour when called with empty arrays). Patch by Joel Perras <joel.per...@gmail.com>. ------------------------------------------------------------------------ [2010-08-26 18:13:54] 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 ------------------------------------------------------------------------ [2008-12-21 22:05:12] 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. ------------------------------------------------------------------------ [2005-10-13 15:07:12] 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) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=34857&edit=1