1--TEST--
2Test uasort() function : usage variations - unexpected values for 'array_arg' argument
3--FILE--
4<?php
5/* Prototype  : bool uasort(array $array_arg, string $cmp_function)
6 * Description: Sort an array with a user-defined comparison function and maintain index association
7 * Source code: ext/standard/array.c
8*/
9
10/*
11* Testing uasort() function by passing different scalar/nonscalar values as 'array_arg' argument
12*/
13
14echo "*** Testing uasort() : unexpected values for 'array_arg' ***\n";
15
16// Comparison function
17/* Prototype : int cmp_function(mixed $value1, mixed $value2)
18 * Parameters : $value1 and $value2 - values to be compared
19 * Return value : 0 - if both values are same
20 *                1 - if value1 is greater than value2
21 *               -1 - if value1 is less than value2
22 * Description : compares value1 and value2
23 */
24function cmp_function($value1, $value2)
25{
26  if($value1 == $value2) {
27    return 0;
28  }
29  else if($value1 > $value2) {
30    return 1;
31  }
32  else {
33    return -1;
34  }
35}
36
37//get an unset variable
38$unset_var = 10;
39unset ($unset_var);
40
41// get resource variable
42$fp = fopen(__FILE__,'r');
43
44//array of values to iterate over
45$input_values = array(
46
47       // int data
48/*1*/  0,
49       1,
50       12345,
51       -2345,
52
53       // float data
54/*5*/  10.5,
55       -10.5,
56       10.1234567e8,
57       10.7654321E-8,
58       .5,
59
60       // null data
61/*10*/ NULL,
62       null,
63
64       // boolean data
65/*12*/ true,
66       false,
67       TRUE,
68       FALSE,
69
70       // empty data
71/*16*/ "",
72       '',
73
74       // string data
75/*18*/ "string",
76       'string',
77
78       // resource data
79/*20*/ $fp,
80
81       // undefined data
82       @$undefined_var,
83
84       // unset data
85/*22*/ @$unset_var,
86);
87
88// loop through each value of input_values
89for($count = 0; $count < count($input_values); $count++) {
90  echo "-- Iteration ".($count + 1)." --\n";
91  var_dump( uasort($input_values[$count], 'cmp_function') );
92};
93
94//closing resource
95fclose($fp);
96echo "Done"
97?>
98--EXPECTF--
99*** Testing uasort() : unexpected values for 'array_arg' ***
100-- Iteration 1 --
101
102Warning: uasort() expects parameter 1 to be array, int given in %s on line %d
103NULL
104-- Iteration 2 --
105
106Warning: uasort() expects parameter 1 to be array, int given in %s on line %d
107NULL
108-- Iteration 3 --
109
110Warning: uasort() expects parameter 1 to be array, int given in %s on line %d
111NULL
112-- Iteration 4 --
113
114Warning: uasort() expects parameter 1 to be array, int given in %s on line %d
115NULL
116-- Iteration 5 --
117
118Warning: uasort() expects parameter 1 to be array, float given in %s on line %d
119NULL
120-- Iteration 6 --
121
122Warning: uasort() expects parameter 1 to be array, float given in %s on line %d
123NULL
124-- Iteration 7 --
125
126Warning: uasort() expects parameter 1 to be array, float given in %s on line %d
127NULL
128-- Iteration 8 --
129
130Warning: uasort() expects parameter 1 to be array, float given in %s on line %d
131NULL
132-- Iteration 9 --
133
134Warning: uasort() expects parameter 1 to be array, float given in %s on line %d
135NULL
136-- Iteration 10 --
137
138Warning: uasort() expects parameter 1 to be array, null given in %s on line %d
139NULL
140-- Iteration 11 --
141
142Warning: uasort() expects parameter 1 to be array, null given in %s on line %d
143NULL
144-- Iteration 12 --
145
146Warning: uasort() expects parameter 1 to be array, bool given in %s on line %d
147NULL
148-- Iteration 13 --
149
150Warning: uasort() expects parameter 1 to be array, bool given in %s on line %d
151NULL
152-- Iteration 14 --
153
154Warning: uasort() expects parameter 1 to be array, bool given in %s on line %d
155NULL
156-- Iteration 15 --
157
158Warning: uasort() expects parameter 1 to be array, bool given in %s on line %d
159NULL
160-- Iteration 16 --
161
162Warning: uasort() expects parameter 1 to be array, string given in %s on line %d
163NULL
164-- Iteration 17 --
165
166Warning: uasort() expects parameter 1 to be array, string given in %s on line %d
167NULL
168-- Iteration 18 --
169
170Warning: uasort() expects parameter 1 to be array, string given in %s on line %d
171NULL
172-- Iteration 19 --
173
174Warning: uasort() expects parameter 1 to be array, string given in %s on line %d
175NULL
176-- Iteration 20 --
177
178Warning: uasort() expects parameter 1 to be array, resource given in %s on line %d
179NULL
180-- Iteration 21 --
181
182Warning: uasort() expects parameter 1 to be array, null given in %s on line %d
183NULL
184-- Iteration 22 --
185
186Warning: uasort() expects parameter 1 to be array, null given in %s on line %d
187NULL
188Done
189