1--TEST--
2Test krsort() function : usage variations - unexpected values for 'sort_flags' argument
3--FILE--
4<?php
5/* Prototype  : bool krsort(array &array_arg [, int sort_flags])
6 * Description: Sort an array by key in reverse order, maintaining key to data correlation
7 * Source code: ext/standard/array.c
8*/
9
10/*
11 * Testing krsort() by providing different unexpected values for flag argument
12*/
13
14echo "*** Testing krsort() : usage variations ***\n";
15
16//get an unset variable
17$unset_var = 10;
18unset ($unset_var);
19
20// resource variable
21$fp = fopen(__FILE__, "r");
22
23// an array for checking unexpected behavior
24$unsorted_values = array(10 => 10, 2 => 2, 45 => 45);
25
26//array of unexpected values to iterate over
27$unexpected_values = array (
28
29       // int data
30/*1*/  -2345,
31
32       // float data
33/*2*/  10.5,
34       -10.5,
35       10.5e2,
36       10.6E-2,
37       .5,
38
39       // null data
40/*7*/  NULL,
41       null,
42
43       // boolean data
44/*9*/  true,
45       false,
46       TRUE,
47       FALSE,
48
49       // empty data
50/*13*/ "",
51       '',
52
53       // string data
54/*15*/ "string",
55       'string',
56
57       // object data
58/*16*/ new stdclass(),
59
60       // undefined data
61/*17*/ @undefined_var,
62
63       // unset data
64/*18*/ @unset_var,
65
66       // resource variable
67/*19*/ $fp
68
69);
70
71// loop though each element of the array and check the working of krsort()
72// when 'sort_flags' argument is supplied with different values
73echo "\n-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument --\n";
74
75$counter = 1;
76for($index = 0; $index < count($unexpected_values); $index ++) {
77  echo "-- Iteration $counter --\n";
78  $value = $unexpected_values [$index];
79  $temp_array = $unsorted_values;
80  var_dump( krsort($temp_array, $value) );
81  var_dump($temp_array);
82  $counter++;
83}
84
85echo "Done";
86?>
87--EXPECTF--
88*** Testing krsort() : usage variations ***
89
90-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument --
91-- Iteration 1 --
92bool(true)
93array(3) {
94  [45]=>
95  int(45)
96  [10]=>
97  int(10)
98  [2]=>
99  int(2)
100}
101-- Iteration 2 --
102bool(true)
103array(3) {
104  [45]=>
105  int(45)
106  [2]=>
107  int(2)
108  [10]=>
109  int(10)
110}
111-- Iteration 3 --
112bool(true)
113array(3) {
114  [45]=>
115  int(45)
116  [10]=>
117  int(10)
118  [2]=>
119  int(2)
120}
121-- Iteration 4 --
122bool(true)
123array(3) {
124  [45]=>
125  int(45)
126  [10]=>
127  int(10)
128  [2]=>
129  int(2)
130}
131-- Iteration 5 --
132bool(true)
133array(3) {
134  [45]=>
135  int(45)
136  [10]=>
137  int(10)
138  [2]=>
139  int(2)
140}
141-- Iteration 6 --
142bool(true)
143array(3) {
144  [45]=>
145  int(45)
146  [10]=>
147  int(10)
148  [2]=>
149  int(2)
150}
151-- Iteration 7 --
152bool(true)
153array(3) {
154  [45]=>
155  int(45)
156  [10]=>
157  int(10)
158  [2]=>
159  int(2)
160}
161-- Iteration 8 --
162bool(true)
163array(3) {
164  [45]=>
165  int(45)
166  [10]=>
167  int(10)
168  [2]=>
169  int(2)
170}
171-- Iteration 9 --
172bool(true)
173array(3) {
174  [45]=>
175  int(45)
176  [10]=>
177  int(10)
178  [2]=>
179  int(2)
180}
181-- Iteration 10 --
182bool(true)
183array(3) {
184  [45]=>
185  int(45)
186  [10]=>
187  int(10)
188  [2]=>
189  int(2)
190}
191-- Iteration 11 --
192bool(true)
193array(3) {
194  [45]=>
195  int(45)
196  [10]=>
197  int(10)
198  [2]=>
199  int(2)
200}
201-- Iteration 12 --
202bool(true)
203array(3) {
204  [45]=>
205  int(45)
206  [10]=>
207  int(10)
208  [2]=>
209  int(2)
210}
211-- Iteration 13 --
212
213Warning: krsort() expects parameter 2 to be integer, string given in %s on line %d
214bool(false)
215array(3) {
216  [10]=>
217  int(10)
218  [2]=>
219  int(2)
220  [45]=>
221  int(45)
222}
223-- Iteration 14 --
224
225Warning: krsort() expects parameter 2 to be integer, string given in %s on line %d
226bool(false)
227array(3) {
228  [10]=>
229  int(10)
230  [2]=>
231  int(2)
232  [45]=>
233  int(45)
234}
235-- Iteration 15 --
236
237Warning: krsort() expects parameter 2 to be integer, string given in %s on line %d
238bool(false)
239array(3) {
240  [10]=>
241  int(10)
242  [2]=>
243  int(2)
244  [45]=>
245  int(45)
246}
247-- Iteration 16 --
248
249Warning: krsort() expects parameter 2 to be integer, string given in %s on line %d
250bool(false)
251array(3) {
252  [10]=>
253  int(10)
254  [2]=>
255  int(2)
256  [45]=>
257  int(45)
258}
259-- Iteration 17 --
260
261Warning: krsort() expects parameter 2 to be integer, object given in %s on line %d
262bool(false)
263array(3) {
264  [10]=>
265  int(10)
266  [2]=>
267  int(2)
268  [45]=>
269  int(45)
270}
271-- Iteration 18 --
272
273Warning: krsort() expects parameter 2 to be integer, string given in %s on line %d
274bool(false)
275array(3) {
276  [10]=>
277  int(10)
278  [2]=>
279  int(2)
280  [45]=>
281  int(45)
282}
283-- Iteration 19 --
284
285Warning: krsort() expects parameter 2 to be integer, string given in %s on line %d
286bool(false)
287array(3) {
288  [10]=>
289  int(10)
290  [2]=>
291  int(2)
292  [45]=>
293  int(45)
294}
295-- Iteration 20 --
296
297Warning: krsort() expects parameter 2 to be integer, resource given in %s on line %d
298bool(false)
299array(3) {
300  [10]=>
301  int(10)
302  [2]=>
303  int(2)
304  [45]=>
305  int(45)
306}
307Done
308