min/max oddities
| From: | Thies C. Arntzen | Date: | Sun, 07 Nov 1999 17:12:43 +0000 |
| Subject: | min/max oddities | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-5935@lists.php.net to get a copy of this message | ||
leon just reported a bug in min() and max() (PHP 3 and PHP 4 behave
different).
the problem is even "bigger":
<?
var_dump(min(5,1,10, "hello"));
var_dump(min(array(5,1,10, "hello")));
var_dump(max(1,10, "hello"));
var_dump(max(array(1,10, "hello")));
?>
produces:
Content-Type: text/html
string(5) "hello"
int(1)
int(10)
string(5) "hello"
that's because array_data_compare() (in basic_functions) is produces
different results from is_smaller_function() (libzend)
array_data_compare is the PHP 3 behaviour!
so, what's the way to go:
1) use is_smaller_function() in array_data_compare()
2) create and array_data_compare_pval() and use that for min and max.
way 2 would be 100% downward compatible but 1 would be the "right way" as
is_smaller_function() is the function that the core language uses!
tc