From: Andrei Zmievski Date: Thu, 13 Jul 2006 22:26:42 +0000 (+0000) Subject: Update array_sum() and array_product() (U). X-Git-Tag: RELEASE_1_0_0RC1~2431 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8254d82d70fdf0c561d4f7dcc90b78e006ff012;p=php Update array_sum() and array_product() (U). --- diff --git a/ext/standard/array.c b/ext/standard/array.c index 8fce763e7b..dc6f619ad7 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4142,31 +4142,25 @@ PHP_FUNCTION(array_rand) } /* }}} */ -/* {{{ proto mixed array_sum(array input) +/* {{{ proto mixed array_sum(array input) U Returns the sum of the array entries */ PHP_FUNCTION(array_sum) { - zval **input, + zval *input, **entry, entry_n; - int argc = ZEND_NUM_ARGS(); HashPosition pos; double dval; - if (argc != 1 || zend_get_parameters_ex(argc, &input) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) { return; } ZVAL_LONG(return_value, 0); - 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; - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos)) { + for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos); + zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &pos) == SUCCESS; + zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos)) { if (Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT) continue; @@ -4189,34 +4183,28 @@ PHP_FUNCTION(array_sum) } /* }}} */ -/* {{{ proto mixed array_product(array input) +/* {{{ proto mixed array_product(array input) U Returns the product of the array entries */ PHP_FUNCTION(array_product) { - zval **input, + zval *input, **entry, entry_n; - int argc = ZEND_NUM_ARGS(); HashPosition pos; double dval; - if (argc != 1 || zend_get_parameters_ex(argc, &input) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) { return; } - if (!zend_hash_num_elements(Z_ARRVAL_PP(input))) { + if (!zend_hash_num_elements(Z_ARRVAL_P(input))) { RETURN_LONG(0); } 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; - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos)) { + for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos); + zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &pos) == SUCCESS; + zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos)) { if (Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT) continue; diff --git a/unicode-progress.txt b/unicode-progress.txt index b56cb16ffe..ee5bd8ff69 100644 --- a/unicode-progress.txt +++ b/unicode-progress.txt @@ -55,9 +55,6 @@ ext/standard array_pad() Params API, test - array_product() - Params API, test - array_push(), array_pop(), array_shift(), array_unshift() Params API, test @@ -79,9 +76,6 @@ ext/standard array_slice() Params API, test - array_sum() - Params API, test - array_unique() Params API, test @@ -105,7 +99,7 @@ ext/standard Either port strnatcmp() to support Unicode or maybe use ICU's numeric collation usort(), uasort(), uksort() - function name normalization, FCI cache + Params API, callback name normalization, FCI cache Completed @@ -116,6 +110,8 @@ ext/standard array_chunk() array_merge() array_merge_recursive() + array_product() + array_sum() compact() count() min()