1--TEST--
2Test 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
17echo "*** Testing arsort() : object functionality ***\n";
18
19// class declaration for integer objects
20class 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
31class 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
62echo "\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;
66var_dump(arsort($temp_array) );
67var_dump($temp_array);
68
69// testing arsort() function by supplying string object array, flag value is defualt
70$temp_array = $unsorted_str_obj;
71var_dump(arsort($temp_array) );
72var_dump($temp_array);
73
74echo "\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;
77var_dump(arsort($temp_array, SORT_REGULAR) );
78var_dump($temp_array);
79
80// testing arsort() function by supplying string object array, flag value = SORT_REGULAR
81$temp_array = $unsorted_str_obj;
82var_dump(arsort($temp_array, SORT_REGULAR) );
83var_dump($temp_array);
84
85echo "Done\n";
86?>
87--EXPECTF--
88*** Testing arsort() : object functionality ***
89
90Fatal error: Class 'for_integer_asort' not found in %sarsort_object1.php on line %d