php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42691 array_reduce: initial parameter should allow non-numeric values
Submitted: 2007-09-18 02:27 UTC Modified: 2012-08-06 01:06 UTC
Votes:3
Avg. Score:3.3 ± 1.2
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: tjerk dot meesters at muvee dot com Assigned: googleguy (profile)
Status: Closed Package: Arrays related
PHP Version: 5.2.4 OS: Linux 2.6
Private report: No CVE-ID: None
 [2007-09-18 02:27 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-08 21:33 UTC] jani@php.net
-Package: Feature/Change Request +Package: Arrays related
 [2012-08-05 22:33 UTC] 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.
 [2012-08-06 01:06 UTC] googleguy@php.net
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


 [2012-08-06 01:06 UTC] googleguy@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: googleguy
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 11:01:34 2024 UTC