Re: Feature request for min() and max()
| From: | Andi Gutmans | Date: | Mon, 20 Nov 2000 05:23:48 +0000 |
| Subject: | Re: Feature request for min() and max() | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-38532@lists.php.net to get a copy of this message | ||
I didn't quite understand what this patch does. Can you explain on a PHP level?
Andi
At 08:21 PM 11/19/00 -0700, Ron Chmara wrote:
Well, since it was a weekend, let's give it another 24 hours, eh? If nobody's objected by then, I'll add it. -Ronabop Colin Viebrock wrote: 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). _________________________________________________________________--- Andi Gutmans <andi@zend.com> http://www.zend.com/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 mustcontain at least 1 element");+ RETURN_FALSE; + } } else { - php_error(E_WARNING, "min: array must contain atleast 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 mustcontain at least 1 element");+ RETURN_FALSE; + } + } else { *return_value = **result; zval_copy_ctor(return_value); - } else { - php_error(E_WARNING, "max: array must contain atleast 1 element");- RETURN_FALSE; } } else { pval ***args = (pval ***) emalloc(sizeof(pval**)*ZEND_NUM_ARGS()); -- Brought to you from iBop the iMac, a MacOS, Win95, Win98, LinuxPPC machine, which is currently in MacOS land. Your bopping may vary. -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net