]> granicus.if.org Git - php/commitdiff
Fixed array_type_data_compare(). I want strings to always differ from
authorStig Venaas <venaas@php.net>
Sun, 22 Oct 2000 11:18:21 +0000 (11:18 +0000)
committerStig Venaas <venaas@php.net>
Sun, 22 Oct 2000 11:18:21 +0000 (11:18 +0000)
numbers, but not say 7 and 7.0 to differ.

ext/standard/array.c

index 4c049888bebc66645a9eb6cb9e3353b2400ef895..f6b9ae5708e2896aedce2f2903a4c9e8b1e3f0b6 100644 (file)
@@ -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;
     }