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--EXPECTF--
99*** Testing each() : usage variations ***
100
101-- Iteration 1 --
102
103Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
104
105Warning: Variable passed to each() is not an array or object in %s on line %d
106NULL
107
108-- Iteration 2 --
109
110Warning: Variable passed to each() is not an array or object in %s on line %d
111NULL
112
113-- Iteration 3 --
114
115Warning: Variable passed to each() is not an array or object in %s on line %d
116NULL
117
118-- Iteration 4 --
119
120Warning: Variable passed to each() is not an array or object in %s on line %d
121NULL
122
123-- Iteration 5 --
124
125Warning: Variable passed to each() is not an array or object in %s on line %d
126NULL
127
128-- Iteration 6 --
129
130Warning: Variable passed to each() is not an array or object in %s on line %d
131NULL
132
133-- Iteration 7 --
134
135Warning: Variable passed to each() is not an array or object in %s on line %d
136NULL
137
138-- Iteration 8 --
139
140Warning: Variable passed to each() is not an array or object in %s on line %d
141NULL
142
143-- Iteration 9 --
144
145Warning: Variable passed to each() is not an array or object in %s on line %d
146NULL
147
148-- Iteration 10 --
149
150Warning: Variable passed to each() is not an array or object in %s on line %d
151NULL
152
153-- Iteration 11 --
154
155Warning: Variable passed to each() is not an array or object in %s on line %d
156NULL
157
158-- Iteration 12 --
159
160Warning: Variable passed to each() is not an array or object in %s on line %d
161NULL
162
163-- Iteration 13 --
164
165Warning: Variable passed to each() is not an array or object in %s on line %d
166NULL
167
168-- Iteration 14 --
169
170Warning: Variable passed to each() is not an array or object in %s on line %d
171NULL
172
173-- Iteration 15 --
174
175Warning: Variable passed to each() is not an array or object in %s on line %d
176NULL
177
178-- Iteration 16 --
179
180Warning: Variable passed to each() is not an array or object in %s on line %d
181NULL
182
183-- Iteration 17 --
184
185Warning: Variable passed to each() is not an array or object in %s on line %d
186NULL
187
188-- Iteration 18 --
189bool(false)
190
191-- Iteration 19 --
192
193Warning: Variable passed to each() is not an array or object in %s on line %d
194NULL
195
196-- Iteration 20 --
197
198Warning: Variable passed to each() is not an array or object in %s on line %d
199NULL
200
201-- Iteration 21 --
202
203Warning: Variable passed to each() is not an array or object in %s on line %d
204NULL
205
206-- Iteration 22 --
207bool(false)
208
209-- Iteration 23 --
210
211Warning: Variable passed to each() is not an array or object in %s on line %d
212NULL
213
214-- Iteration 24 --
215
216Warning: Variable passed to each() is not an array or object in %s on line %d
217NULL
218
219-- Iteration 25 --
220
221Warning: Variable passed to each() is not an array or object in %s on line %d
222NULL
223Done
224