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

From: Date: Mon, 20 Nov 2000 13:38:26 +0000
Subject: Re: Feature request for min() and max()
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-38595@lists.php.net to get a copy of this message
At 08:31 AM 11/20/2000 -0500, Colin Viebrock wrote:
[Mon, 20 Nov 2000] Andi Gutmans said: I didn't quite understand what this patch does. Can you explain on a PHP level? My *plan* was for this patch to change the behaviour of max() and min(), so that if you pass it one scalar value, instead of returning a "wrong number of arguments" warning, it just passes back the value of the scalar. So ... <? echo min(12); ?> Outputs "12", not an error. I'm not sure if my code is right though, thus my post to the list for someone else to take a quick look before committing it.
I don't think that's a very good idea. If the user gives the min() function an invalid value, he should get an error. Anyway, the easiest way to this would simply be to change:
                if (zend_get_parameters_ex(1, &arr) == FAILURE || (*arr)->type != IS_ARRAY) {
                        WRONG_PARAM_COUNT;
                }
To:
                if (zend_get_parameters_ex(1, &arr) == FAILURE) {
                        WRONG_PARAM_COUNT;
                }
                if ((*arr)->type != IS_ARRAY) {
                        *return_value = **arr;
                        zval_copy_ctor(return_value);
                        return;
                }
Adding an if .. else is really kind-of unneccessary. -Sterling

« previous php.dev (#38595) next »