Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16913 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74775 invoked by uid 1010); 26 Jun 2005 22:29:36 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 74760 invoked from network); 26 Jun 2005 22:29:36 -0000 Received: from unknown (HELO infaze.com.au) (127.0.0.1) by localhost with SMTP; 26 Jun 2005 22:29:36 -0000 X-Host-Fingerprint: 202.138.0.110 stiletto.hotkey.net.au Linux 2.4/2.6 Received: from ([202.138.0.110:55557] helo=stiletto.hotkey.net.au) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id 33/5A-00424-A4C2FB24 for ; Sun, 26 Jun 2005 18:29:35 -0400 Received: from [192.168.0.200] (81.146-142-203.dart.iprimus.net.au [203.142.146.81]) by stiletto.hotkey.net.au (8.11.6/8.11.6) with ESMTP id j5QMUNY29613 for ; Mon, 27 Jun 2005 08:30:26 +1000 Message-ID: <42BF2C34.1070504@infaze.com.au> Date: Mon, 27 Jun 2005 08:29:08 +1000 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) Gecko/20050325 X-Accept-Language: en, en-us MIME-Version: 1.0 To: internals@lists.php.net X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/mixed; boundary="------------030700010404010106010207" Subject: [PATCH] allow array_reduce to have a mixed starting value From: david.tulloh@infaze.com.au (David Tulloh) --------------030700010404010106010207 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I opened bug #33447 the other day which is a feature request to allow array_reduce to have a mixed starting value. It currently will only accept integers which I feel is an odd limitation since the array can hold any value. This is a trivial patch to array_reduce which removes this limitation. All the tests passed with this modification (that passed without it). I also included a test file which tests the new functionality and provides a few examples of what it could be useful for. David --------------030700010404010106010207 Content-Type: text/x-patch; name="array_reduce.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="array_reduce.patch" Index: ext/standard/array.c =================================================================== RCS file: /repository/php-src/ext/standard/array.c,v retrieving revision 1.304 diff -u -b -w -B -r1.304 array.c --- ext/standard/array.c 21 Jun 2005 12:10:51 -0000 1.304 +++ ext/standard/array.c 24 Jun 2005 02:40:29 -0000 @@ -3992,7 +3992,7 @@ /* }}} */ -/* {{{ proto mixed array_reduce(array input, mixed callback [, int initial]) +/* {{{ proto mixed array_reduce(array input, mixed callback [, mixed initial]) Iteratively reduce the array to a single value via the callback. */ PHP_FUNCTION(array_reduce) { @@ -4027,7 +4027,6 @@ ALLOC_ZVAL(result); *result = **initial; zval_copy_ctor(result); - convert_to_long(result); INIT_PZVAL(result); } else { MAKE_STD_ZVAL(result); --------------030700010404010106010207 Content-Type: text/plain; name="bug33447.phpt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="bug33447.phpt" --TEST-- Bug #33447 - array_reduce should have a mixed starting value --FILE-- --EXPECT-- array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } int(15) int(1200) int(1) string(15) "page1page2page3" string(15) "page1page2page3" string(21) "hi lodpage1page2page3" --------------030700010404010106010207--