1--TEST--
2Test each() function : usage variations - arrays of different data types
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 arrays of different data types as $arr argument 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// arrays of different data types to be passed as $arr
38$inputs = array(
39
40       // int data
41/*1*/  'int' => array(
42	   0,
43       1,
44       12345,
45       -2345,
46       ),
47
48       // float data
49/*2*/  'float' => array(
50       10.5,
51       -10.5,
52       12.3456789000e10,
53       12.3456789000E-10,
54       .5,
55       ),
56
57       // null data
58/*3*/ 'null' => array(
59       NULL,
60       null,
61       ),
62
63       // boolean data
64/*4*/ 'bool' => array(
65       true,
66       false,
67       TRUE,
68       FALSE,
69       ),
70
71       // empty data
72/*5*/ 'empty string' => array(
73       "",
74       '',
75       ),
76
77/*6*/ 'empty array' => array(
78       ),
79
80       // string data
81/*7*/ 'string' => array(
82       "string",
83       'string',
84       $heredoc,
85       ),
86
87       // object data
88/*8*/ 'object' => array(
89       new classA(),
90       ),
91
92       // undefined data
93/*9*/ 'undefined' => array(
94       @$undefined_var,
95       ),
96
97       // unset data
98/*10*/ 'unset' => array(
99       @$unset_var,
100       ),
101
102       // resource variable
103/*11*/ 'resource' => array(
104       $fp
105       ),
106);
107
108// loop through each element of $inputs to check the behavior of each()
109$iterator = 1;
110foreach($inputs as $key => $input) {
111  echo "\n-- Iteration $iterator: $key data --\n";
112  var_dump( each($input) );
113  $iterator++;
114};
115
116fclose($fp);
117
118echo "Done";
119?>
120--EXPECTF--
121*** Testing each() : usage variations ***
122
123-- Iteration 1: int data --
124
125Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
126array(4) {
127  [1]=>
128  int(0)
129  ["value"]=>
130  int(0)
131  [0]=>
132  int(0)
133  ["key"]=>
134  int(0)
135}
136
137-- Iteration 2: float data --
138array(4) {
139  [1]=>
140  float(10.5)
141  ["value"]=>
142  float(10.5)
143  [0]=>
144  int(0)
145  ["key"]=>
146  int(0)
147}
148
149-- Iteration 3: null data --
150array(4) {
151  [1]=>
152  NULL
153  ["value"]=>
154  NULL
155  [0]=>
156  int(0)
157  ["key"]=>
158  int(0)
159}
160
161-- Iteration 4: bool data --
162array(4) {
163  [1]=>
164  bool(true)
165  ["value"]=>
166  bool(true)
167  [0]=>
168  int(0)
169  ["key"]=>
170  int(0)
171}
172
173-- Iteration 5: empty string data --
174array(4) {
175  [1]=>
176  string(0) ""
177  ["value"]=>
178  string(0) ""
179  [0]=>
180  int(0)
181  ["key"]=>
182  int(0)
183}
184
185-- Iteration 6: empty array data --
186bool(false)
187
188-- Iteration 7: string data --
189array(4) {
190  [1]=>
191  string(6) "string"
192  ["value"]=>
193  string(6) "string"
194  [0]=>
195  int(0)
196  ["key"]=>
197  int(0)
198}
199
200-- Iteration 8: object data --
201array(4) {
202  [1]=>
203  object(classA)#%d (0) {
204  }
205  ["value"]=>
206  object(classA)#%d (0) {
207  }
208  [0]=>
209  int(0)
210  ["key"]=>
211  int(0)
212}
213
214-- Iteration 9: undefined data --
215array(4) {
216  [1]=>
217  NULL
218  ["value"]=>
219  NULL
220  [0]=>
221  int(0)
222  ["key"]=>
223  int(0)
224}
225
226-- Iteration 10: unset data --
227array(4) {
228  [1]=>
229  NULL
230  ["value"]=>
231  NULL
232  [0]=>
233  int(0)
234  ["key"]=>
235  int(0)
236}
237
238-- Iteration 11: resource data --
239array(4) {
240  [1]=>
241  resource(%d) of type (stream)
242  ["value"]=>
243  resource(%d) of type (stream)
244  [0]=>
245  int(0)
246  ["key"]=>
247  int(0)
248}
249Done
250