Annotation of embedaddon/php/ext/standard/tests/array/arsort_object1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test arsort() function : object functionality - sort objects  
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : bool arsort ( array &$array [, int $asort_flags] )
                      6:  * Description: Sort an array and maintain index association.  
                      7:                 Elements will be arranged from highest to lowest when this function has completed.
                      8:  * Source code: ext/standard/array.c
                      9: */
                     10: 
                     11: /*
                     12:  * testing arsort() by providing integer/string object arrays with following flag values 
                     13:  * 1. Defualt flag value
                     14:  * 2. SORT_REGULAR - compare items normally
                     15: */
                     16: 
                     17: echo "*** Testing arsort() : object functionality ***\n";
                     18: 
                     19: // class declaration for integer objects
                     20: class for_integer_arsort
                     21: {
                     22:   public $class_value;
                     23:   // initializing object member value
                     24:   function __construct($value){
                     25:     $this->class_value = $value;
                     26:   }
                     27: 
                     28: }
                     29: 
                     30: // class declaration for string objects
                     31: class for_string_arsort
                     32: {
                     33:   public $class_value;
                     34:   // initializing object member value
                     35:   function __construct($value){
                     36:     $this->class_value = $value;
                     37:    }
                     38: 
                     39:   // return string value
                     40:   function __tostring() {
                     41:    return (string)$this->value;
                     42:   }
                     43: 
                     44: }
                     45: 
                     46: // array of integer objects
                     47: $unsorted_int_obj = array ( 
                     48:   1 => new for_integer_arsort(11), 2 =>  new for_integer_asort(66),
                     49:   3 => new for_integer_arsort(23), 4 => new for_integer_asort(-5),
                     50:   5 => new for_integer_arsort(0.001), 6 => new for_integer_asort(0)
                     51: );
                     52: 
                     53: // array of string objects
                     54: $unsorted_str_obj = array ( 
                     55:   "a" => new for_string_arsort("axx"), "b" => new for_string_asort("t"),
                     56:   "c" => new for_string_arsort("w"), "d" => new for_string_asort("py"),
                     57:   "e" => new for_string_arsort("apple"), "f" => new for_string_asort("Orange"),
                     58:   "g" => new for_string_arsort("Lemon"), "h" => new for_string_asort("aPPle")
                     59: );
                     60: 
                     61: 
                     62: echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is defualt --\n";
                     63: 
                     64: // testing arsort() function by supplying integer object array, flag value is defualt
                     65: $temp_array = $unsorted_int_obj;
                     66: var_dump(arsort($temp_array) );
                     67: var_dump($temp_array);
                     68: 
                     69: // testing arsort() function by supplying string object array, flag value is defualt
                     70: $temp_array = $unsorted_str_obj;
                     71: var_dump(arsort($temp_array) );
                     72: var_dump($temp_array);
                     73: 
                     74: echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n";
                     75: // testing arsort() function by supplying integer object array, flag value = SORT_REGULAR
                     76: $temp_array = $unsorted_int_obj;
                     77: var_dump(arsort($temp_array, SORT_REGULAR) );
                     78: var_dump($temp_array);
                     79: 
                     80: // testing arsort() function by supplying string object array, flag value = SORT_REGULAR
                     81: $temp_array = $unsorted_str_obj;
                     82: var_dump(arsort($temp_array, SORT_REGULAR) );
                     83: var_dump($temp_array);
                     84: 
                     85: echo "Done\n";
                     86: ?>
                     87: --EXPECTF--
                     88: *** Testing arsort() : object functionality ***
                     89: 
                     90: Fatal error: Class 'for_integer_asort' not found in %sarsort_object1.php on line %d

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>