# [PATCH] array_product()

- Thread: https://externals.io/message/19810
- Original archive: https://news-web.php.net/php.internals/19810
- Started by Arpad Ray on 2005-10-29T07:03:09+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #19810 — Arpad Ray — 2005-10-29T07:03:09+00:00

URL: https://externals.io/message/19810#19810

The `array_product()` function is completely broken. I've filed a bug at 
http://bugs.php.net/bug.php?id=35014 describing the problem, but to summarise 
it returns 0 for all valid input and when the input is an empty array.

I've also posted a patch, which fixes everything for me. I would appreciate 
any feedback, especially since this is my first patch :)

Thanks,
Arpad Ray

Index: ext/standard/array.c
===================================================================
RCS file: /repository/php-src/ext/standard/array.c,v
retrieving revision 1.308.2.10
diff -u -u -b -B -r1.308.2.10 array.c
--- ext/standard/array.c        28 Oct 2005 09:57:35 -0000      1.308.2.10
+++ ext/standard/array.c        29 Oct 2005 06:04:22 -0000
@@ -3997,7 +3997,12 @@
                return;
        }

-       ZVAL_LONG(return_value, 0);
+       if (zend_hash_num_elements(Z_ARRVAL_PP(input)) == 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array must 
contain at least one element");
+               return;
+       }
+
+       ZVAL_LONG(return_value, 1);

        for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos);
                 zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void 
**)&entry, &pos) == SUCCESS;
