1--TEST--
2Test array_reverse() function : usage variations - unexpected values for 'preserve_keys' argument
3--FILE--
4<?php
5/* Prototype  : array array_reverse(array $array [, bool $preserve_keys])
6 * Description: Return input as a new array with the order of the entries reversed
7 * Source code: ext/standard/array.c
8*/
9
10/*
11 * testing the functionality of array_reverse() by giving unexpected values for $preserve_keys argument
12*/
13
14echo "*** Testing array_reverse() : usage variations ***\n";
15
16// Initialise the array
17$array = array("a" => "green", "red", "blue", "red", "orange", "pink");
18
19//get an unset variable
20$unset_var = 10;
21unset ($unset_var);
22
23//get a resource variable
24$fp = fopen(__FILE__, "r");
25
26//get a class
27class classA
28{
29  public function __toString(){
30    return "Class A object";
31  }
32}
33
34//array of values to iterate over
35$preserve_keys = 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.5e10,
47       10.6E-10,
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       true,
63       false,
64       TRUE,
65       FALSE,
66
67       // empty data
68/*21*/
69       "",
70       '',
71
72       // object data
73       new classA(),
74
75       // undefined data
76       @$undefined_var,
77
78       // unset data
79       @$unset_var,
80
81       // resource variable
82/*26*/ $fp
83
84);
85
86// loop through each element of the array $preserve_keys to check the behavior of array_reverse()
87$iterator = 1;
88foreach($preserve_keys as $preserve_key) {
89  echo "-- Iteration $iterator --\n";
90  var_dump( array_reverse($array, $preserve_key) );
91  $iterator++;
92};
93
94// close the file resouce used
95fclose($fp);
96
97echo "Done";
98?>
99--EXPECTF--
100*** Testing array_reverse() : usage variations ***
101-- Iteration 1 --
102array(6) {
103  [0]=>
104  string(4) "pink"
105  [1]=>
106  string(6) "orange"
107  [2]=>
108  string(3) "red"
109  [3]=>
110  string(4) "blue"
111  [4]=>
112  string(3) "red"
113  ["a"]=>
114  string(5) "green"
115}
116-- Iteration 2 --
117array(6) {
118  [4]=>
119  string(4) "pink"
120  [3]=>
121  string(6) "orange"
122  [2]=>
123  string(3) "red"
124  [1]=>
125  string(4) "blue"
126  [0]=>
127  string(3) "red"
128  ["a"]=>
129  string(5) "green"
130}
131-- Iteration 3 --
132array(6) {
133  [4]=>
134  string(4) "pink"
135  [3]=>
136  string(6) "orange"
137  [2]=>
138  string(3) "red"
139  [1]=>
140  string(4) "blue"
141  [0]=>
142  string(3) "red"
143  ["a"]=>
144  string(5) "green"
145}
146-- Iteration 4 --
147array(6) {
148  [4]=>
149  string(4) "pink"
150  [3]=>
151  string(6) "orange"
152  [2]=>
153  string(3) "red"
154  [1]=>
155  string(4) "blue"
156  [0]=>
157  string(3) "red"
158  ["a"]=>
159  string(5) "green"
160}
161-- Iteration 5 --
162array(6) {
163  [4]=>
164  string(4) "pink"
165  [3]=>
166  string(6) "orange"
167  [2]=>
168  string(3) "red"
169  [1]=>
170  string(4) "blue"
171  [0]=>
172  string(3) "red"
173  ["a"]=>
174  string(5) "green"
175}
176-- Iteration 6 --
177array(6) {
178  [4]=>
179  string(4) "pink"
180  [3]=>
181  string(6) "orange"
182  [2]=>
183  string(3) "red"
184  [1]=>
185  string(4) "blue"
186  [0]=>
187  string(3) "red"
188  ["a"]=>
189  string(5) "green"
190}
191-- Iteration 7 --
192array(6) {
193  [4]=>
194  string(4) "pink"
195  [3]=>
196  string(6) "orange"
197  [2]=>
198  string(3) "red"
199  [1]=>
200  string(4) "blue"
201  [0]=>
202  string(3) "red"
203  ["a"]=>
204  string(5) "green"
205}
206-- Iteration 8 --
207array(6) {
208  [4]=>
209  string(4) "pink"
210  [3]=>
211  string(6) "orange"
212  [2]=>
213  string(3) "red"
214  [1]=>
215  string(4) "blue"
216  [0]=>
217  string(3) "red"
218  ["a"]=>
219  string(5) "green"
220}
221-- Iteration 9 --
222array(6) {
223  [4]=>
224  string(4) "pink"
225  [3]=>
226  string(6) "orange"
227  [2]=>
228  string(3) "red"
229  [1]=>
230  string(4) "blue"
231  [0]=>
232  string(3) "red"
233  ["a"]=>
234  string(5) "green"
235}
236-- Iteration 10 --
237
238Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d
239NULL
240-- Iteration 11 --
241
242Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d
243NULL
244-- Iteration 12 --
245
246Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d
247NULL
248-- Iteration 13 --
249
250Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d
251NULL
252-- Iteration 14 --
253
254Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d
255NULL
256-- Iteration 15 --
257array(6) {
258  [0]=>
259  string(4) "pink"
260  [1]=>
261  string(6) "orange"
262  [2]=>
263  string(3) "red"
264  [3]=>
265  string(4) "blue"
266  [4]=>
267  string(3) "red"
268  ["a"]=>
269  string(5) "green"
270}
271-- Iteration 16 --
272array(6) {
273  [0]=>
274  string(4) "pink"
275  [1]=>
276  string(6) "orange"
277  [2]=>
278  string(3) "red"
279  [3]=>
280  string(4) "blue"
281  [4]=>
282  string(3) "red"
283  ["a"]=>
284  string(5) "green"
285}
286-- Iteration 17 --
287array(6) {
288  [4]=>
289  string(4) "pink"
290  [3]=>
291  string(6) "orange"
292  [2]=>
293  string(3) "red"
294  [1]=>
295  string(4) "blue"
296  [0]=>
297  string(3) "red"
298  ["a"]=>
299  string(5) "green"
300}
301-- Iteration 18 --
302array(6) {
303  [0]=>
304  string(4) "pink"
305  [1]=>
306  string(6) "orange"
307  [2]=>
308  string(3) "red"
309  [3]=>
310  string(4) "blue"
311  [4]=>
312  string(3) "red"
313  ["a"]=>
314  string(5) "green"
315}
316-- Iteration 19 --
317array(6) {
318  [4]=>
319  string(4) "pink"
320  [3]=>
321  string(6) "orange"
322  [2]=>
323  string(3) "red"
324  [1]=>
325  string(4) "blue"
326  [0]=>
327  string(3) "red"
328  ["a"]=>
329  string(5) "green"
330}
331-- Iteration 20 --
332array(6) {
333  [0]=>
334  string(4) "pink"
335  [1]=>
336  string(6) "orange"
337  [2]=>
338  string(3) "red"
339  [3]=>
340  string(4) "blue"
341  [4]=>
342  string(3) "red"
343  ["a"]=>
344  string(5) "green"
345}
346-- Iteration 21 --
347array(6) {
348  [0]=>
349  string(4) "pink"
350  [1]=>
351  string(6) "orange"
352  [2]=>
353  string(3) "red"
354  [3]=>
355  string(4) "blue"
356  [4]=>
357  string(3) "red"
358  ["a"]=>
359  string(5) "green"
360}
361-- Iteration 22 --
362array(6) {
363  [0]=>
364  string(4) "pink"
365  [1]=>
366  string(6) "orange"
367  [2]=>
368  string(3) "red"
369  [3]=>
370  string(4) "blue"
371  [4]=>
372  string(3) "red"
373  ["a"]=>
374  string(5) "green"
375}
376-- Iteration 23 --
377
378Warning: array_reverse() expects parameter 2 to be boolean, object given in %s on line %d
379NULL
380-- Iteration 24 --
381array(6) {
382  [0]=>
383  string(4) "pink"
384  [1]=>
385  string(6) "orange"
386  [2]=>
387  string(3) "red"
388  [3]=>
389  string(4) "blue"
390  [4]=>
391  string(3) "red"
392  ["a"]=>
393  string(5) "green"
394}
395-- Iteration 25 --
396array(6) {
397  [0]=>
398  string(4) "pink"
399  [1]=>
400  string(6) "orange"
401  [2]=>
402  string(3) "red"
403  [3]=>
404  string(4) "blue"
405  [4]=>
406  string(3) "red"
407  ["a"]=>
408  string(5) "green"
409}
410-- Iteration 26 --
411
412Warning: array_reverse() expects parameter 2 to be boolean, resource given in %s on line %d
413NULL
414Done
415