Annotation of embedaddon/php/ext/standard/tests/array/asort_variation2.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test 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:
15: echo "*** Testing asort() : usage variations ***\n";
16:
17: //get an unset variable
18: $unset_var = 10;
19: unset ($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 arugment is supplied with different values from $unexpected_values
74: echo "\n-- Testing asort() by supplying different unexpected values for 'sort_flags' argument --\n";
75:
76: $counter = 1;
77: for($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:
86: echo "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 --
93: bool(true)
94: array(3) {
95: [2]=>
96: int(2)
97: [1]=>
98: int(10)
99: [3]=>
100: int(45)
101: }
102: -- Iteration 2 --
103: bool(true)
104: array(3) {
105: [1]=>
106: int(10)
1.1.1.2 ! misho 107: [2]=>
! 108: int(2)
1.1 misho 109: [3]=>
110: int(45)
111: }
112: -- Iteration 3 --
113: bool(true)
114: array(3) {
115: [2]=>
116: int(2)
117: [1]=>
118: int(10)
119: [3]=>
120: int(45)
121: }
122: -- Iteration 4 --
123: bool(true)
124: array(3) {
125: [2]=>
126: int(2)
127: [1]=>
128: int(10)
129: [3]=>
130: int(45)
131: }
132: -- Iteration 5 --
133: bool(true)
134: array(3) {
135: [2]=>
136: int(2)
137: [1]=>
138: int(10)
139: [3]=>
140: int(45)
141: }
142: -- Iteration 6 --
143: bool(true)
144: array(3) {
145: [2]=>
146: int(2)
147: [1]=>
148: int(10)
149: [3]=>
150: int(45)
151: }
152: -- Iteration 7 --
153: bool(true)
154: array(3) {
155: [2]=>
156: int(2)
157: [1]=>
158: int(10)
159: [3]=>
160: int(45)
161: }
162: -- Iteration 8 --
163: bool(true)
164: array(3) {
165: [2]=>
166: int(2)
167: [1]=>
168: int(10)
169: [3]=>
170: int(45)
171: }
172: -- Iteration 9 --
173: bool(true)
174: array(3) {
175: [2]=>
176: int(2)
177: [1]=>
178: int(10)
179: [3]=>
180: int(45)
181: }
182: -- Iteration 10 --
183: bool(true)
184: array(3) {
185: [2]=>
186: int(2)
187: [1]=>
188: int(10)
189: [3]=>
190: int(45)
191: }
192: -- Iteration 11 --
193: bool(true)
194: array(3) {
195: [2]=>
196: int(2)
197: [1]=>
198: int(10)
199: [3]=>
200: int(45)
201: }
202: -- Iteration 12 --
203: bool(true)
204: array(3) {
205: [2]=>
206: int(2)
207: [1]=>
208: int(10)
209: [3]=>
210: int(45)
211: }
212: -- Iteration 13 --
213:
214: Warning: asort() expects parameter 2 to be long, string given in %s on line %d
215: bool(false)
216: array(3) {
217: [1]=>
218: int(10)
219: [2]=>
220: int(2)
221: [3]=>
222: int(45)
223: }
224: -- Iteration 14 --
225:
226: Warning: asort() expects parameter 2 to be long, string given in %s on line %d
227: bool(false)
228: array(3) {
229: [1]=>
230: int(10)
231: [2]=>
232: int(2)
233: [3]=>
234: int(45)
235: }
236: -- Iteration 15 --
237:
238: Warning: asort() expects parameter 2 to be long, string given in %s on line %d
239: bool(false)
240: array(3) {
241: [1]=>
242: int(10)
243: [2]=>
244: int(2)
245: [3]=>
246: int(45)
247: }
248: -- Iteration 16 --
249:
250: Warning: asort() expects parameter 2 to be long, string given in %s on line %d
251: bool(false)
252: array(3) {
253: [1]=>
254: int(10)
255: [2]=>
256: int(2)
257: [3]=>
258: int(45)
259: }
260: -- Iteration 17 --
261:
262: Warning: asort() expects parameter 2 to be long, object given in %s on line %d
263: bool(false)
264: array(3) {
265: [1]=>
266: int(10)
267: [2]=>
268: int(2)
269: [3]=>
270: int(45)
271: }
272: -- Iteration 18 --
273:
274: Warning: asort() expects parameter 2 to be long, string given in %s on line %d
275: bool(false)
276: array(3) {
277: [1]=>
278: int(10)
279: [2]=>
280: int(2)
281: [3]=>
282: int(45)
283: }
284: -- Iteration 19 --
285:
286: Warning: asort() expects parameter 2 to be long, string given in %s on line %d
287: bool(false)
288: array(3) {
289: [1]=>
290: int(10)
291: [2]=>
292: int(2)
293: [3]=>
294: int(45)
295: }
296: -- Iteration 20 --
297:
298: Warning: asort() expects parameter 2 to be long, resource given in %s on line %d
299: bool(false)
300: array(3) {
301: [1]=>
302: int(10)
303: [2]=>
304: int(2)
305: [3]=>
306: int(45)
307: }
308: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>