Annotation of embedaddon/php/ext/standard/tests/array/usort_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test usort() function : usage variations - Pass different data types as $array_arg arg
3: --FILE--
4: <?php
5: /* Prototype : bool usort(array $array_arg, string $cmp_function)
6: * Description: Sort an array by values using a user-defined comparison function
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * Pass different data types as $array_arg argument to usort() to test behaviour
12: */
13:
14: echo "*** Testing usort() : usage variations ***\n";
15:
16: // Initialise function arguments not being substituted
17: function cmp_function($value1, $value2)
18: {
19: if($value1 == $value2) {
20: return 0;
21: }
22: else if($value1 > $value2) {
23: return 1;
24: }
25: else {
26: return -1;
27: }
28: }
29:
30: //get an unset variable
31: $unset_var = 10;
32: unset ($unset_var);
33:
34: // get a class
35: class classA
36: {
37: public function __toString() {
38: return "Class A object";
39: }
40: }
41:
42: // heredoc string
43: $heredoc = <<<EOT
44: hello world
45: EOT;
46:
47: // get a resource variable
48: $fp = fopen(__FILE__, "r");
49:
50: // unexpected values to be passed to $array_arg argument
51: $inputs = array(
52:
53: // int data
54: /*1*/ 0,
55: 1,
56: 12345,
57: -2345,
58:
59: // float data
60: /*5*/ 10.5,
61: -10.5,
62: 12.3456789000e10,
63: 12.3456789000E-10,
64: .5,
65:
66: // null data
67: /*10*/ NULL,
68: null,
69:
70: // boolean data
71: /*12*/ true,
72: false,
73: TRUE,
74: FALSE,
75:
76: // empty data
77: /*16*/ "",
78: '',
79: array(),
80:
81: // string data
82: /*19*/ "string",
83: 'string',
84: $heredoc,
85:
86: // object data
87: /*22*/ new classA(),
88:
89: // undefined data
90: /*23*/ @$undefined_var,
91:
92: // unset data
93: /*24*/ @$unset_var,
94:
95: // resource variable
96: /*25*/ $fp
97: );
98:
99: // loop through each element of $inputs to check the behavior of usort()
100: $iterator = 1;
101: foreach($inputs as $input) {
102: echo "\n-- Iteration $iterator --\n";
103: var_dump( usort($input, 'cmp_function') );
104: $iterator++;
105: };
106:
107: //closing resource
108: fclose($fp);
109: ?>
110: ===DONE===
111: --EXPECTF--
112: *** Testing usort() : usage variations ***
113:
114: -- Iteration 1 --
115:
116: Warning: usort() expects parameter 1 to be array, integer given in %s on line %d
117: NULL
118:
119: -- Iteration 2 --
120:
121: Warning: usort() expects parameter 1 to be array, integer given in %s on line %d
122: NULL
123:
124: -- Iteration 3 --
125:
126: Warning: usort() expects parameter 1 to be array, integer given in %s on line %d
127: NULL
128:
129: -- Iteration 4 --
130:
131: Warning: usort() expects parameter 1 to be array, integer given in %s on line %d
132: NULL
133:
134: -- Iteration 5 --
135:
136: Warning: usort() expects parameter 1 to be array, double given in %s on line %d
137: NULL
138:
139: -- Iteration 6 --
140:
141: Warning: usort() expects parameter 1 to be array, double given in %s on line %d
142: NULL
143:
144: -- Iteration 7 --
145:
146: Warning: usort() expects parameter 1 to be array, double given in %s on line %d
147: NULL
148:
149: -- Iteration 8 --
150:
151: Warning: usort() expects parameter 1 to be array, double given in %s on line %d
152: NULL
153:
154: -- Iteration 9 --
155:
156: Warning: usort() expects parameter 1 to be array, double given in %s on line %d
157: NULL
158:
159: -- Iteration 10 --
160:
161: Warning: usort() expects parameter 1 to be array, null given in %s on line %d
162: NULL
163:
164: -- Iteration 11 --
165:
166: Warning: usort() expects parameter 1 to be array, null given in %s on line %d
167: NULL
168:
169: -- Iteration 12 --
170:
171: Warning: usort() expects parameter 1 to be array, boolean given in %s on line %d
172: NULL
173:
174: -- Iteration 13 --
175:
176: Warning: usort() expects parameter 1 to be array, boolean given in %s on line %d
177: NULL
178:
179: -- Iteration 14 --
180:
181: Warning: usort() expects parameter 1 to be array, boolean given in %s on line %d
182: NULL
183:
184: -- Iteration 15 --
185:
186: Warning: usort() expects parameter 1 to be array, boolean given in %s on line %d
187: NULL
188:
189: -- Iteration 16 --
190:
191: Warning: usort() expects parameter 1 to be array, string given in %s on line %d
192: NULL
193:
194: -- Iteration 17 --
195:
196: Warning: usort() expects parameter 1 to be array, string given in %s on line %d
197: NULL
198:
199: -- Iteration 18 --
200: bool(true)
201:
202: -- Iteration 19 --
203:
204: Warning: usort() expects parameter 1 to be array, string given in %s on line %d
205: NULL
206:
207: -- Iteration 20 --
208:
209: Warning: usort() expects parameter 1 to be array, string given in %s on line %d
210: NULL
211:
212: -- Iteration 21 --
213:
214: Warning: usort() expects parameter 1 to be array, string given in %s on line %d
215: NULL
216:
217: -- Iteration 22 --
218:
219: Warning: usort() expects parameter 1 to be array, object given in %s on line %d
220: NULL
221:
222: -- Iteration 23 --
223:
224: Warning: usort() expects parameter 1 to be array, null given in %s on line %d
225: NULL
226:
227: -- Iteration 24 --
228:
229: Warning: usort() expects parameter 1 to be array, null given in %s on line %d
230: NULL
231:
232: -- Iteration 25 --
233:
234: Warning: usort() expects parameter 1 to be array, resource given in %s on line %d
235: NULL
236: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>