Re: Feature request for min() and max()

From: Date: Mon, 20 Nov 2000 03:21:27 +0000
Subject: Re: Feature request for min() and max()
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-38524@lists.php.net to get a copy of this message
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). > > _________________________________________________________________ > 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()); -- Brought to you from iBop the iMac, a MacOS, Win95, Win98, LinuxPPC machine, which is currently in MacOS land. Your bopping may vary.

« previous php.dev (#38524) next »