Req #42691 [Opn->Csd]: array_reduce: initial parameter should allow non-numeric values
| From: | googleguy@php.net | Date: | Mon, 06 Aug 2012 01:06:51 +0000 |
| Subject: | Req #42691 [Opn->Csd]: array_reduce: initial parameter should allow non-numeric values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-172459@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
Updated by: googleguy@php.net
Reported by: tjerk dot meesters at muvee dot com
Summary: array_reduce: initial parameter should allow
non-numeric values
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Arrays related
Operating System: Linux 2.6
PHP Version: 5.2.4
-Assigned To:
+Assigned To: googleguy
Block user comment: N
Private report: N
New Comment:
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php
Previous Comments:
------------------------------------------------------------------------
[2012-08-05 22:33:41] lonnyk at gmail dot com
This has been added in 5.3. I just tested it with PHP 5.4.5-dev and it works.
------------------------------------------------------------------------
[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