1--TEST--
2Test shuffle() function : usage variations  - unexpected values for 'array_arg' argument
3--FILE--
4<?php
5/* Prototype  : bool shuffle(array $array_arg)
6 * Description: Randomly shuffle the contents of an array
7 * Source code: ext/standard/array.c
8*/
9
10/*
11* Test behaviour of shuffle() when unexpected values are passed for 'array_arg'
12* argument and verify that function outputs required warning messages wherever applicable
13*/
14
15echo "*** Testing shuffle() : with unexpected values for 'array_arg' argument ***\n";
16
17
18//get an unset variable
19$unset_var = 10;
20unset ($unset_var);
21
22//get a resource variable
23$fp = fopen(__FILE__, "r");
24
25//define a class
26class test
27{
28  var $t = 10;
29  function __toString()
30  {
31    return "object";
32  }
33}
34
35//array of values to iterate over
36$values = array(
37
38       // int data
39/*1*/  0,
40       1,
41       12345,
42       -2345,
43
44       // float data
45/*5*/  10.5,
46       -10.5,
47       12.3456789000e10,
48       12.3456789000E-10,
49       .5,
50
51       // null data
52/*10*/ NULL,
53       null,
54
55       // boolean data
56/*12*/ true,
57       false,
58       TRUE,
59       FALSE,
60
61       // empty data
62/*16*/ "",
63       '',
64
65       // string data
66/*18*/ "string",
67       'string',
68
69       // object data
70/*20*/ new test(),
71
72       // undefined data
73/*21*/ @$undefined_var,
74
75       // unset data
76/*22*/ @$unset_var,
77
78/*23*/ // resource data
79       $fp
80);
81
82// loop through the array to test shuffle() function
83// with each element of the array
84$count = 1;
85foreach($values as $value) {
86  echo "\n-- Iteration $count --\n";
87  var_dump( shuffle($value) );
88  $count++;
89};
90
91// closing the resource
92fclose($fp);
93
94echo "Done";
95?>
96--EXPECTF--
97*** Testing shuffle() : with unexpected values for 'array_arg' argument ***
98
99-- Iteration 1 --
100
101Warning: shuffle() expects parameter 1 to be array, integer given in %s on line %d
102bool(false)
103
104-- Iteration 2 --
105
106Warning: shuffle() expects parameter 1 to be array, integer given in %s on line %d
107bool(false)
108
109-- Iteration 3 --
110
111Warning: shuffle() expects parameter 1 to be array, integer given in %s on line %d
112bool(false)
113
114-- Iteration 4 --
115
116Warning: shuffle() expects parameter 1 to be array, integer given in %s on line %d
117bool(false)
118
119-- Iteration 5 --
120
121Warning: shuffle() expects parameter 1 to be array, float given in %s on line %d
122bool(false)
123
124-- Iteration 6 --
125
126Warning: shuffle() expects parameter 1 to be array, float given in %s on line %d
127bool(false)
128
129-- Iteration 7 --
130
131Warning: shuffle() expects parameter 1 to be array, float given in %s on line %d
132bool(false)
133
134-- Iteration 8 --
135
136Warning: shuffle() expects parameter 1 to be array, float given in %s on line %d
137bool(false)
138
139-- Iteration 9 --
140
141Warning: shuffle() expects parameter 1 to be array, float given in %s on line %d
142bool(false)
143
144-- Iteration 10 --
145
146Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
147bool(false)
148
149-- Iteration 11 --
150
151Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
152bool(false)
153
154-- Iteration 12 --
155
156Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line %d
157bool(false)
158
159-- Iteration 13 --
160
161Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line %d
162bool(false)
163
164-- Iteration 14 --
165
166Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line %d
167bool(false)
168
169-- Iteration 15 --
170
171Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line %d
172bool(false)
173
174-- Iteration 16 --
175
176Warning: shuffle() expects parameter 1 to be array, string given in %s on line %d
177bool(false)
178
179-- Iteration 17 --
180
181Warning: shuffle() expects parameter 1 to be array, string given in %s on line %d
182bool(false)
183
184-- Iteration 18 --
185
186Warning: shuffle() expects parameter 1 to be array, string given in %s on line %d
187bool(false)
188
189-- Iteration 19 --
190
191Warning: shuffle() expects parameter 1 to be array, string given in %s on line %d
192bool(false)
193
194-- Iteration 20 --
195
196Warning: shuffle() expects parameter 1 to be array, object given in %s on line %d
197bool(false)
198
199-- Iteration 21 --
200
201Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
202bool(false)
203
204-- Iteration 22 --
205
206Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
207bool(false)
208
209-- Iteration 23 --
210
211Warning: shuffle() expects parameter 1 to be array, resource given in %s on line %d
212bool(false)
213Done
214
215