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