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