I'll make it set the defaut value to NULL, that addresses the problem you've
described and maintains acceptable behaviour for the original problem.
Ilia
On August 9, 2003 02:09 am, Moriyoshi Koizumi wrote:
> I don't think using 0 as the initial value by default is a good idea.
> because array_reduce() can take any kind of element other than integer.
>
> <?php
> $a = array("a", "b", "c");
> $lambda = create_function('$a, $b', 'return $a . $b;');
> var_dump(array_reduce($a, $lambda));
> ?>
>
> [Before this patch]
> string(3) "abc"
>
> [After this patch]
> string(4) "0abc"
>
> Those results imply a significant BC break. I don't know what *is* the
> correct behaviour though.
>
> Moriyoshi
>
> "Ilia Alshanetsky" <[EMAIL PROTECTED]> wrote:
> > iliaa Fri Aug 8 19:50:36 2003 EDT
> >
> > Modified files:
> > /php-src/ext/standard array.c
> > Log:
> > Fixed bug #24980 (array_reduce() uses first element as default running
> > total).
> > Fixed memory leak that can be replicated using the function example on
> > http://www.php.net/array_reduce
> >
> >
> > Index: php-src/ext/standard/array.c
> > diff -u php-src/ext/standard/array.c:1.238
> > php-src/ext/standard/array.c:1.239 ---
> > php-src/ext/standard/array.c:1.238 Tue Aug 5 06:29:03 2003
> > +++ php-src/ext/standard/array.c Fri Aug 8 19:50:36 2003
> > @@ -21,7 +21,7 @@
> >
> > +----------------------------------------------------------------------+
> > */
> >
> > -/* $Id: array.c,v 1.238 2003/08/05 10:29:03 zeev Exp $ */
> > +/* $Id: array.c,v 1.239 2003/08/08 23:50:36 iliaa Exp $ */
> >
> > #include "php.h"
> > #include "php_ini.h"
> > @@ -3374,7 +3374,9 @@
> >
> > if (ZEND_NUM_ARGS() > 2) {
> > result = *initial;
> > - zval_add_ref(&result);
> > + } else {
> > + MAKE_STD_ZVAL(result);
> > + ZVAL_LONG(result, 0);
> > }
> >
> > /* (zval **)input points to an element of argument stack
> >
> >
> >
> > --
> > PHP CVS Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php