diff options
author | Andrei Zmievski <andrei@php.net> | 2008-12-13 00:38:29 +0000 |
---|---|---|
committer | Andrei Zmievski <andrei@php.net> | 2008-12-13 00:38:29 +0000 |
commit | 844799cfd565ed3abd3a217312b0779318e06e19 (patch) | |
tree | d8b8c4f03d394f04fe4d60166c350a4f6773dcf4 | |
parent | d6b537e8cae137124366976beb70b13471c8b980 (diff) | |
download | php-git-844799cfd565ed3abd3a217312b0779318e06e19.tar.gz |
MFH
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/standard/array.c | 28 | ||||
-rw-r--r-- | ext/standard/tests/array/array_unique_error.phpt | 6 | ||||
-rw-r--r-- | ext/standard/tests/array/array_unique_variation1.phpt | 99 | ||||
-rw-r--r-- | ext/standard/tests/array/array_unique_variation2.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/array/array_unique_variation6.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/array/array_unique_variation8.phpt | 2 |
7 files changed, 70 insertions, 71 deletions
@@ -1,6 +1,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2009, PHP 5.2.9 +- Added optional sorting type flag parameter to array_unique(), default is + SORT_REGULAR. (Andrei) - Fixed security issue in imagerotate(), background colour isn't validated correctly with a non truecolour image. (Scott) diff --git a/ext/standard/array.c b/ext/standard/array.c index 64189ff33a..58039650cf 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2813,12 +2813,11 @@ PHP_FUNCTION(array_change_key_case) } /* }}} */ -/* {{{ proto array array_unique(array input) +/* {{{ proto array array_unique(array input [, int sort_flags]) Removes duplicate values from array */ PHP_FUNCTION(array_unique) { - zval **array, *tmp; - HashTable *target_hash; + zval *array, *tmp; Bucket *p; struct bucketindex { Bucket *b; @@ -2826,34 +2825,31 @@ PHP_FUNCTION(array_unique) }; struct bucketindex *arTmp, *cmpdata, *lastkept; unsigned int i; + long sort_type = SORT_REGULAR; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) { + return; } + set_compare_func(sort_type TSRMLS_CC); + array_init(return_value); - zend_hash_copy(Z_ARRVAL_P(return_value), target_hash, (copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*)); + zend_hash_copy(Z_ARRVAL_P(return_value), Z_ARRVAL_P(array), (copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*)); - if (target_hash->nNumOfElements <= 1) { /* nothing to do */ + if (Z_ARRVAL_P(array)->nNumOfElements <= 1) { /* nothing to do */ return; } /* create and sort array with pointers to the target_hash buckets */ - arTmp = (struct bucketindex *) pemalloc((target_hash->nNumOfElements + 1) * sizeof(struct bucketindex), target_hash->persistent); + arTmp = (struct bucketindex *) pemalloc((Z_ARRVAL_P(array)->nNumOfElements + 1) * sizeof(struct bucketindex), Z_ARRVAL_P(array)->persistent); if (!arTmp) { RETURN_FALSE; } - for (i = 0, p = target_hash->pListHead; p; i++, p = p->pListNext) { + for (i = 0, p = Z_ARRVAL_P(array)->pListHead; p; i++, p = p->pListNext) { arTmp[i].b = p; arTmp[i].i = i; } arTmp[i].b = NULL; - set_compare_func(SORT_STRING TSRMLS_CC); zend_qsort((void *) arTmp, i, sizeof(struct bucketindex), array_data_compare TSRMLS_CC); /* go through the sorted array and delete duplicates from the copy */ @@ -2879,7 +2875,7 @@ PHP_FUNCTION(array_unique) } } } - pefree(arTmp, target_hash->persistent); + pefree(arTmp, Z_ARRVAL_P(array)->persistent); } /* }}} */ diff --git a/ext/standard/tests/array/array_unique_error.phpt b/ext/standard/tests/array/array_unique_error.phpt index 59d458a2ac..9da3dfcad6 100644 --- a/ext/standard/tests/array/array_unique_error.phpt +++ b/ext/standard/tests/array/array_unique_error.phpt @@ -17,7 +17,7 @@ var_dump( array_unique() ); echo "\n-- Testing array_unique() function with more than expected no. of arguments --\n"; $input = array(1, 2); $extra_arg = 10; -var_dump( array_unique($input, $extra_arg) ); +var_dump( array_unique($input, SORT_NUMERIC, $extra_arg) ); echo "Done"; ?> @@ -26,11 +26,11 @@ echo "Done"; -- Testing array_unique() function with zero arguments -- -Warning: Wrong parameter count for array_unique() in %s on line %d +Warning: array_unique() expects at least 1 parameter, 0 given in %s on line %d NULL -- Testing array_unique() function with more than expected no. of arguments -- -Warning: Wrong parameter count for array_unique() in %s on line %d +Warning: array_unique() expects at most 2 parameters, 3 given in %s on line %d NULL Done diff --git a/ext/standard/tests/array/array_unique_variation1.phpt b/ext/standard/tests/array/array_unique_variation1.phpt index 3a9ae10ddb..a7774ef92a 100644 --- a/ext/standard/tests/array/array_unique_variation1.phpt +++ b/ext/standard/tests/array/array_unique_variation1.phpt @@ -98,97 +98,98 @@ echo "Done"; *** Testing array_unique() : Passing non array values to $input argument *** -- Iteration 1 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL -- Iteration 2 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL -- Iteration 3 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL -- Iteration 4 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL -- Iteration 5 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 6 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 7 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 8 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 9 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 10 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL -- Iteration 11 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL -- Iteration 12 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL -- Iteration 13 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL -- Iteration 14 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL -- Iteration 15 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL -- Iteration 16 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 17 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 18 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 19 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 20 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 21 -- -array(0) { -} + +Warning: array_unique() expects parameter 1 to be array, object given in %s on line %d +NULL -- Iteration 22 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL -- Iteration 23 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL -- Iteration 24 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) -Done
\ No newline at end of file +Warning: array_unique() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_unique_variation2.phpt b/ext/standard/tests/array/array_unique_variation2.phpt index c91aa0f04d..e9003f7d04 100644 --- a/ext/standard/tests/array/array_unique_variation2.phpt +++ b/ext/standard/tests/array/array_unique_variation2.phpt @@ -74,7 +74,7 @@ $inputs = array ( $iterator = 1; foreach($inputs as $input) { echo "-- Iteration $iterator --\n"; - var_dump( array_unique($input) ); + var_dump( array_unique($input, SORT_STRING) ); $iterator++; } diff --git a/ext/standard/tests/array/array_unique_variation6.phpt b/ext/standard/tests/array/array_unique_variation6.phpt index fd8b226fab..15a46518b7 100644 --- a/ext/standard/tests/array/array_unique_variation6.phpt +++ b/ext/standard/tests/array/array_unique_variation6.phpt @@ -29,7 +29,7 @@ $input = array( 5 => $value4 ); -var_dump( array_unique($input) ); +var_dump( array_unique($input, SORT_STRING) ); echo "Done"; ?> diff --git a/ext/standard/tests/array/array_unique_variation8.phpt b/ext/standard/tests/array/array_unique_variation8.phpt index ae6e8bb5c1..6cf343221f 100644 --- a/ext/standard/tests/array/array_unique_variation8.phpt +++ b/ext/standard/tests/array/array_unique_variation8.phpt @@ -22,7 +22,7 @@ $input = array( array(1, 2, 3, 1) ); -var_dump( array_unique($input) ); +var_dump( array_unique($input, SORT_STRING) ); echo "Done"; ?> |