Req #34857 [Com]: Change array_combine behavoiur
| From: | joel dot perras+phpbugs at gmail dot com | Date: | Thu, 26 Aug 2010 16:13:54 +0000 |
| Subject: | Req #34857 [Com]: Change array_combine behavoiur | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-153818@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=34857&edit=1
ID: 34857
Comment by: joel dot perras+phpbugs at gmail dot com
Reported by: stochnagara at hotmail dot com
Summary: Change array_combine behavoiur
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
PHP Version: 5.1.0RC1
Block user comment: N
New Comment:
Patch against the current svn HEAD of trunk available here:
http://paste.roguecoders.com/p/16e1e953e8b1890bcaaba00eb8408dd7.txt
Previous Comments:
------------------------------------------------------------------------
[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