Req #42691 [Com]: array_reduce: initial parameter should allow non-numeric values
| From: | lonnyk at gmail dot com | Date: | Sun, 05 Aug 2012 22:33:41 +0000 |
| Subject: | Req #42691 [Com]: array_reduce: initial parameter should allow non-numeric values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-172456@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=42691&edit=1
ID: 42691
Comment by: lonnyk at gmail dot com
Reported by: tjerk dot meesters at muvee dot com
Summary: array_reduce: initial parameter should allow
non-numeric values
Status: Open
Type: Feature/Change Request
Package: Arrays related
Operating System: Linux 2.6
PHP Version: 5.2.4
Block user comment: N
Private report: N
New Comment:
This has been added in 5.3. I just tested it with PHP 5.4.5-dev and it works.
Previous Comments:
------------------------------------------------------------------------
[2007-09-18 02:27:59] tjerk dot meesters at muvee dot com
Description:
------------
array_reduce() accepts an initial value to be passed as the first argument in the callback function
instead of NULL.
However, this initial value - if passed - is converted to an int. This is probably because the more
common use of this idiom is for mathematical reduction.
It would be helpful to allow other types to be passed such as strings or objects.
Note: this ticket is a duplicate for #42566, but the reporter never bothered to follow up.
Reproduce code:
---------------
<?php
echo array_reduce(
array(' ','world'),
create_function(
'$total,$new',
'return $total.$new;'
),
'hello'
);
?>
Expected result:
----------------
hello world
Actual result:
--------------
0 world
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=42691&edit=1