From: Stig Venaas Date: Sun, 22 Oct 2000 11:18:21 +0000 (+0000) Subject: Fixed array_type_data_compare(). I want strings to always differ from X-Git-Tag: php-4.0.4RC3~568 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e8c7fd7f5f5b6aae7073af9e33be720cdc858bd5;p=php Fixed array_type_data_compare(). I want strings to always differ from numbers, but not say 7 and 7.0 to differ. --- diff --git a/ext/standard/array.c b/ext/standard/array.c index 4c049888be..f6b9ae5708 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -256,6 +256,9 @@ PHP_FUNCTION(count) /* Numbers are always smaller than strings int this function as it * anyway doesn't make much sense to compare two different data types. * This keeps it consistant and simple. + * + * This is not correct any more, if you want this behavior, use + * array_type_data_compare(). */ static int array_data_compare(const void *a, const void *b) { @@ -346,7 +349,8 @@ static int array_natural_case_compare(const void *a, const void *b) return array_natural_general_compare(a, b, 1); } -/* Compare types first, and compare data only if same type */ +/* Compare types first, if exactly one argument is a string, return the + * type difference, thus numbers are always smaller than strings */ static int array_type_data_compare(const void *a, const void *b) { Bucket *f; @@ -364,10 +368,9 @@ static int array_type_data_compare(const void *a, const void *b) second = *((pval **) s->pData); diff = first->type - second->type; - if (diff) + if (diff && ((first->type == IS_STRING) || (second->type == IS_STRING))) return diff; - if (ARRAYG(compare_func)(&result, first, second) == FAILURE) { return 0; }