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