Feature request for min() and max()

From: Date: Fri, 17 Nov 2000 22:38:11 +0000
Subject: Feature request for min() and max()
Groups: php.dev 
Request: Send a blank email to php-dev+get-38456@lists.php.net to get a copy of this message
It's seems a bit silly to me for min() and max() to fail if you only supply it one argument that isn't an array. It means an extra level of checking in user's functions to deal with it. So, here is a patch to array.c to make min($a) return the value of $a if it is a scalar. Could someone who understands the code better than I check it over for correctness and apply it (if it is deemed worthy, which I think it is). _________________________________________________________________ Colin Viebrock easyDNS Technologies Co-Founder control your domain http://www.easyDNS.com [cmv@vincent php4]$ diff -u ext/standard/array.c ext/standard/new.array.c --- ext/standard/array.c Thu Nov 9 11:32:54 2000 +++ ext/standard/new.array.c Fri Nov 17 17:34:24 2000 @@ -907,15 +907,20 @@ if (argc == 1) { pval **arr; - if (zend_get_parameters_ex(1, &arr) == FAILURE || (*arr)->type != IS_ARRAY) { + if (zend_get_parameters_ex(1, &arr) == FAILURE) { WRONG_PARAM_COUNT; } - if (zend_hash_minmax((*arr)->value.ht, array_data_compare, 0, (void **) &result)==SUCCESS) { - *return_value = **result; - zval_copy_ctor(return_value); + if ((*arr)->type == IS_ARRAY) { + if (zend_hash_minmax((*arr)->value.ht, array_data_compare, 0, (void **) &result)==SUCCESS) { + *return_value = **result; + zval_copy_ctor(return_value); + } else { + php_error(E_WARNING, "min: array must contain at least 1 element"); + RETURN_FALSE; + } } else { - php_error(E_WARNING, "min: array must contain at least 1 element"); - RETURN_FALSE; + *return_value = **arr; + zval_copy_ctor(return_value); } } else { pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS()); @@ -959,15 +964,20 @@ if (argc == 1) { pval **arr; - if (zend_get_parameters_ex(1, &arr) == FAILURE || (*arr)->type != IS_ARRAY) { + if (zend_get_parameters_ex(1, &arr) == FAILURE) { WRONG_PARAM_COUNT; } - if (zend_hash_minmax((*arr)->value.ht, array_data_compare, 1, (void **) &result)==SUCCESS) { + if ((*arr)->type == IS_ARRAY) { + if (zend_hash_minmax((*arr)->value.ht, array_data_compare, 1, (void **) &result)==SUCCESS) { + *return_value = **result; + zval_copy_ctor(return_value); + } else { + php_error(E_WARNING, "max: array must contain at least 1 element"); + RETURN_FALSE; + } + } else { *return_value = **result; zval_copy_ctor(return_value); - } else { - php_error(E_WARNING, "max: array must contain at least 1 element"); - RETURN_FALSE; } } else { pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS());

« previous php.dev (#38456) next »