1--TEST--
2Test krsort() function : object functionality - sort objects
3--FILE--
4<?php
5/*
6 * testing krsort() by providing array of integer/string objects with following flag values:
7 *  1.Default flag value
8 *  2.SORT_REGULAR - compare items normally
9*/
10
11echo "*** Testing krsort() : object functionality ***\n";
12
13// class declaration for integer objects
14class IntegerObject
15{
16  public $class_value;
17  // initializing object member value
18  function __construct($value){
19    $this->class_value = $value;
20  }
21}
22
23// class declaration for string objects
24class StringObject
25{
26  public $class_value;
27  // initializing object member value
28  function __construct($value){
29    $this->class_value = $value;
30   }
31
32  // return string value
33  function __tostring() {
34   return (string)$this->value;
35  }
36
37}
38
39// array of integer objects with different key values
40$unsorted_int_obj = array (
41  10 => new IntegerObject(11), 20 =>  new IntegerObject(66),
42  3 => new IntegerObject(23), 4 => new IntegerObject(-5),
43  50 => new IntegerObject(0.001), 6 => new IntegerObject(0)
44);
45
46// array of string objects with different key values
47$unsorted_str_obj = array (
48  "axx" => new StringObject("axx"), "t" => new StringObject("t"),
49  "w" => new StringObject("w"), "py" => new StringObject("py"),
50  "apple" => new StringObject("apple"), "Orange" => new StringObject("Orange"),
51  "Lemon" => new StringObject("Lemon"), "aPPle" => new StringObject("aPPle")
52);
53
54
55echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is default --\n";
56
57// testing krsort() function by supplying integer object array, flag value is default
58$temp_array = $unsorted_int_obj;
59var_dump(krsort($temp_array) );
60var_dump($temp_array);
61
62// testing krsort() function by supplying string object array, flag value is default
63$temp_array = $unsorted_str_obj;
64var_dump(krsort($temp_array) );
65var_dump($temp_array);
66
67echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n";
68// testing krsort() function by supplying integer object array, flag value = SORT_REGULAR
69$temp_array = $unsorted_int_obj;
70var_dump(krsort($temp_array, SORT_REGULAR) );
71var_dump($temp_array);
72
73// testing krsort() function by supplying string object array, flag value = SORT_REGULAR
74$temp_array = $unsorted_str_obj;
75var_dump(krsort($temp_array, SORT_REGULAR) );
76var_dump($temp_array);
77
78echo "Done\n";
79?>
80--EXPECTF--
81*** Testing krsort() : object functionality ***
82
83-- Testing krsort() by supplying various object arrays, 'flag' value is default --
84bool(true)
85array(6) {
86  [50]=>
87  object(IntegerObject)#%d (1) {
88    ["class_value"]=>
89    float(0.001)
90  }
91  [20]=>
92  object(IntegerObject)#%d (1) {
93    ["class_value"]=>
94    int(66)
95  }
96  [10]=>
97  object(IntegerObject)#%d (1) {
98    ["class_value"]=>
99    int(11)
100  }
101  [6]=>
102  object(IntegerObject)#%d (1) {
103    ["class_value"]=>
104    int(0)
105  }
106  [4]=>
107  object(IntegerObject)#%d (1) {
108    ["class_value"]=>
109    int(-5)
110  }
111  [3]=>
112  object(IntegerObject)#%d (1) {
113    ["class_value"]=>
114    int(23)
115  }
116}
117bool(true)
118array(8) {
119  ["w"]=>
120  object(StringObject)#%d (1) {
121    ["class_value"]=>
122    string(1) "w"
123  }
124  ["t"]=>
125  object(StringObject)#%d (1) {
126    ["class_value"]=>
127    string(1) "t"
128  }
129  ["py"]=>
130  object(StringObject)#%d (1) {
131    ["class_value"]=>
132    string(2) "py"
133  }
134  ["axx"]=>
135  object(StringObject)#%d (1) {
136    ["class_value"]=>
137    string(3) "axx"
138  }
139  ["apple"]=>
140  object(StringObject)#%d (1) {
141    ["class_value"]=>
142    string(5) "apple"
143  }
144  ["aPPle"]=>
145  object(StringObject)#%d (1) {
146    ["class_value"]=>
147    string(5) "aPPle"
148  }
149  ["Orange"]=>
150  object(StringObject)#%d (1) {
151    ["class_value"]=>
152    string(6) "Orange"
153  }
154  ["Lemon"]=>
155  object(StringObject)#%d (1) {
156    ["class_value"]=>
157    string(5) "Lemon"
158  }
159}
160
161-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --
162bool(true)
163array(6) {
164  [50]=>
165  object(IntegerObject)#%d (1) {
166    ["class_value"]=>
167    float(0.001)
168  }
169  [20]=>
170  object(IntegerObject)#%d (1) {
171    ["class_value"]=>
172    int(66)
173  }
174  [10]=>
175  object(IntegerObject)#%d (1) {
176    ["class_value"]=>
177    int(11)
178  }
179  [6]=>
180  object(IntegerObject)#%d (1) {
181    ["class_value"]=>
182    int(0)
183  }
184  [4]=>
185  object(IntegerObject)#%d (1) {
186    ["class_value"]=>
187    int(-5)
188  }
189  [3]=>
190  object(IntegerObject)#%d (1) {
191    ["class_value"]=>
192    int(23)
193  }
194}
195bool(true)
196array(8) {
197  ["w"]=>
198  object(StringObject)#%d (1) {
199    ["class_value"]=>
200    string(1) "w"
201  }
202  ["t"]=>
203  object(StringObject)#%d (1) {
204    ["class_value"]=>
205    string(1) "t"
206  }
207  ["py"]=>
208  object(StringObject)#%d (1) {
209    ["class_value"]=>
210    string(2) "py"
211  }
212  ["axx"]=>
213  object(StringObject)#%d (1) {
214    ["class_value"]=>
215    string(3) "axx"
216  }
217  ["apple"]=>
218  object(StringObject)#%d (1) {
219    ["class_value"]=>
220    string(5) "apple"
221  }
222  ["aPPle"]=>
223  object(StringObject)#%d (1) {
224    ["class_value"]=>
225    string(5) "aPPle"
226  }
227  ["Orange"]=>
228  object(StringObject)#%d (1) {
229    ["class_value"]=>
230    string(6) "Orange"
231  }
232  ["Lemon"]=>
233  object(StringObject)#%d (1) {
234    ["class_value"]=>
235    string(5) "Lemon"
236  }
237}
238Done
239