Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:39985 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66512 invoked from network); 16 Aug 2008 13:56:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Aug 2008 13:56:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=cschneid@cschneid.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=cschneid@cschneid.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain cschneid.com from 195.226.6.51 cause and error) X-PHP-List-Original-Sender: cschneid@cschneid.com X-Host-Fingerprint: 195.226.6.51 darkcity.gna.ch Linux 2.6 Received: from [195.226.6.51] ([195.226.6.51:51103] helo=mail.gna.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2B/21-60037-59CD6A84 for ; Sat, 16 Aug 2008 09:56:40 -0400 Received: from localhost (localhost [127.0.0.1]) by darkcity.gna.ch (Postfix) with ESMTP id 44E4C93A1C4; Sat, 16 Aug 2008 16:02:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at gna.ch Received: from mail.gna.ch ([127.0.0.1]) by localhost (gna.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dB02kKS+Ta8U; Sat, 16 Aug 2008 16:01:55 +0200 (CEST) Received: from [192.168.1.43] (84-72-92-81.dclient.hispeed.ch [84.72.92.81]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id AC21F93A1C1; Sat, 16 Aug 2008 16:01:54 +0200 (CEST) Cc: PHP Developers Mailing List Message-ID: <215985D5-981D-43A2-9D25-34C132F3DC20@cschneid.com> To: Marcus Boerger In-Reply-To: <603701944.20080410140201@marcus-boerger.de> Content-Type: multipart/mixed; boundary=Apple-Mail-34-69619503 Mime-Version: 1.0 (Apple Message framework v928.1) X-Priority: 3 (Normal) Date: Sat, 16 Aug 2008 15:56:27 +0200 References: <8A963872-3893-4944-A5BF-C227421C095B@cschneid.com> <603701944.20080410140201@marcus-boerger.de> X-Mailer: Apple Mail (2.928.1) Subject: Re: [PHP-DEV] [PATCH] Allow mixed $initial in array_reduce From: cschneid@cschneid.com (Christian Schneider) --Apple-Mail-34-69619503 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Am 10.04.2008 um 14:02 schrieb Marcus Boerger: > looks good to me. Sidenote: If you cvs add the new test and then do > cvs > di -N, then you get the new files and the stuff you changed in one > diff. > If you do not have access then a) you need to do the cvs add step > manually by editing the CVS/Entries file and putting in a dummy line > for > each new file. And b) you need to find someone to commit this patch > to head > first then 5.3. I attached a single patch including the changes to array_reduce and a test for HEAD, anyone willing to commit it? And is there any chance of including this in PHP 5.3 at this stage? - Chris --Apple-Mail-34-69619503 Content-Disposition: attachment; filename=array_reduce.patch.txt Content-Type: text/plain; x-unix-mode=0664; name="array_reduce.patch.txt" Content-Transfer-Encoding: 7bit ? ext/standard/tests/x Index: ext/standard/array.c =================================================================== RCS file: /repository/php-src/ext/standard/array.c,v retrieving revision 1.460 diff -u -r1.460 array.c --- ext/standard/array.c 10 Aug 2008 17:49:29 -0000 1.460 +++ ext/standard/array.c 16 Aug 2008 13:52:29 -0000 @@ -4354,7 +4354,7 @@ } /* }}} */ -/* {{{ proto mixed array_reduce(array input, mixed callback [, int initial]) U +/* {{{ proto mixed array_reduce(array input, mixed callback [, mixed initial]) U Iteratively reduce the array to a single value via the callback. */ PHP_FUNCTION(array_reduce) { @@ -4365,18 +4365,19 @@ zval *retval; zend_fcall_info fci; zend_fcall_info_cache fci_cache = empty_fcall_info_cache; - long initial; + zval *initial; HashPosition pos; HashTable *htbl; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af|l", &input, &fci, &fci_cache, &initial) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af|z", &input, &fci, &fci_cache, &initial) == FAILURE) { return; } if (ZEND_NUM_ARGS() > 2) { ALLOC_ZVAL(result); + *result = *initial; + zval_copy_ctor(result); INIT_PZVAL(result); - ZVAL_LONG(result, initial); } else { MAKE_STD_ZVAL(result); ZVAL_NULL(result); Index: ext/standard/tests/array/array_reduce.phpt =================================================================== RCS file: ext/standard/tests/array/array_reduce.phpt diff -N ext/standard/tests/array/array_reduce.phpt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ext/standard/tests/array/array_reduce.phpt 16 Aug 2008 13:52:29 -0000 @@ -0,0 +1,79 @@ +--TEST-- +Test array_reduce() function +--INI-- +precision=14 +--FILE-- + 42, 'bar' => 17, 'qux' => -2, 'quux' => 0); +var_dump(array_reduce($array, 'reduce_array', $initial), $initial); + +echo "\n*** Testing array_reduce() to null ***\n"; +function reduce_null($w, $v) { return $w . $v; } +$initial = null; +var_dump(array_reduce($array, 'reduce_null', $initial), $initial); + +echo "\nDone"; +?> +--EXPECTF-- +*** Testing array_reduce() to integer *** +int(61) +int(42) + +*** Testing array_reduce() to float *** +float(6.1) +float(4.2) + +*** Testing array_reduce() to string *** +unicode(23) "quuxfoofoobarquxquxquux" +unicode(4) "quux" + +*** Testing array_reduce() to array *** +array(4) { + [u"foo"]=> + int(44) + [u"bar"]=> + int(18) + [u"qux"]=> + int(0) + [u"quux"]=> + int(1) +} +array(4) { + [u"foo"]=> + int(42) + [u"bar"]=> + int(17) + [u"qux"]=> + int(-2) + [u"quux"]=> + int(0) +} + +*** Testing array_reduce() to null *** +unicode(19) "foofoobarquxquxquux" +NULL + +Done --Apple-Mail-34-69619503 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit --Apple-Mail-34-69619503--