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