1--TEST--
2Test sizeof() function : usage variations - for all scalar types and resource variable
3--FILE--
4<?php
5/* Prototype  : int sizeof($mixed var[, int $mode])
6 * Description: Counts an elements in an array. If Standard PHP library is installed,
7 * it will return the properties of an object.
8 * Source code: ext/standard/basic_functions.c
9 * Alias to functions: count()
10 */
11
12echo "*** Testing sizeof() : usage variations ***\n";
13
14echo "--- Testing sizeof() for all scalar types in default,COUNT_NORMAL and COUNT_RECURSIVE mode ---\n";
15// get a resource variable
16$fp = fopen(__FILE__, "r");
17
18// array containing all scalar types
19$values = array (
20           // int values
21  /* 1  */  0,
22            1,
23
24            // float values
25  /* 3  */   10.5,
26            -10.5,
27            12.3456789000e10,
28            12.3456789000E-10,
29  /* 7  */  .5,
30
31            // NULL values
32  /* 8  */  NULL,
33            null,
34
35            // boolean values
36  /* 10 */  TRUE,
37            FALSE,
38            true,
39  /* 13 */  false,
40
41            // string data
42  /* 14 */  "",
43            '',
44            "string",
45  /* 17 */  'string',
46
47            // undefined variable
48            @$undefined_var,
49
50            // resource variable
51  /* 19 */  $fp
52);
53
54// loop through the each value of the array for 'var' argument and check the behaviour of sizeof()
55$counter = 1;
56for($i = 0; $i < count($values); $i++)
57{
58  echo "-- Iteration $counter --\n";
59
60  $var = $values[$i];
61
62  echo "Default Mode: ";
63  var_dump( sizeof($var) );
64  echo "\n";
65
66  echo "COUNT_NORMAL Mode: ";
67  var_dump( sizeof($var, COUNT_NORMAL) );
68  echo "\n";
69
70  echo "COUNT_RECURSIVE Mode: ";
71  var_dump( sizeof($var, COUNT_RECURSIVE) );
72  echo "\n";
73
74  $counter++;
75}
76
77echo "Done";
78?>
79--EXPECTF--
80*** Testing sizeof() : usage variations ***
81--- Testing sizeof() for all scalar types in default,COUNT_NORMAL and COUNT_RECURSIVE mode ---
82-- Iteration 1 --
83Default Mode:
84Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
85int(1)
86
87COUNT_NORMAL Mode:
88Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
89int(1)
90
91COUNT_RECURSIVE Mode:
92Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
93int(1)
94
95-- Iteration 2 --
96Default Mode:
97Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
98int(1)
99
100COUNT_NORMAL Mode:
101Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
102int(1)
103
104COUNT_RECURSIVE Mode:
105Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
106int(1)
107
108-- Iteration 3 --
109Default Mode:
110Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
111int(1)
112
113COUNT_NORMAL Mode:
114Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
115int(1)
116
117COUNT_RECURSIVE Mode:
118Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
119int(1)
120
121-- Iteration 4 --
122Default Mode:
123Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
124int(1)
125
126COUNT_NORMAL Mode:
127Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
128int(1)
129
130COUNT_RECURSIVE Mode:
131Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
132int(1)
133
134-- Iteration 5 --
135Default Mode:
136Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
137int(1)
138
139COUNT_NORMAL Mode:
140Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
141int(1)
142
143COUNT_RECURSIVE Mode:
144Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
145int(1)
146
147-- Iteration 6 --
148Default Mode:
149Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
150int(1)
151
152COUNT_NORMAL Mode:
153Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
154int(1)
155
156COUNT_RECURSIVE Mode:
157Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
158int(1)
159
160-- Iteration 7 --
161Default Mode:
162Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
163int(1)
164
165COUNT_NORMAL Mode:
166Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
167int(1)
168
169COUNT_RECURSIVE Mode:
170Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
171int(1)
172
173-- Iteration 8 --
174Default Mode:
175Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
176int(0)
177
178COUNT_NORMAL Mode:
179Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
180int(0)
181
182COUNT_RECURSIVE Mode:
183Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
184int(0)
185
186-- Iteration 9 --
187Default Mode:
188Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
189int(0)
190
191COUNT_NORMAL Mode:
192Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
193int(0)
194
195COUNT_RECURSIVE Mode:
196Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
197int(0)
198
199-- Iteration 10 --
200Default Mode:
201Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
202int(1)
203
204COUNT_NORMAL Mode:
205Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
206int(1)
207
208COUNT_RECURSIVE Mode:
209Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
210int(1)
211
212-- Iteration 11 --
213Default Mode:
214Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
215int(1)
216
217COUNT_NORMAL Mode:
218Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
219int(1)
220
221COUNT_RECURSIVE Mode:
222Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
223int(1)
224
225-- Iteration 12 --
226Default Mode:
227Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
228int(1)
229
230COUNT_NORMAL Mode:
231Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
232int(1)
233
234COUNT_RECURSIVE Mode:
235Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
236int(1)
237
238-- Iteration 13 --
239Default Mode:
240Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
241int(1)
242
243COUNT_NORMAL Mode:
244Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
245int(1)
246
247COUNT_RECURSIVE Mode:
248Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
249int(1)
250
251-- Iteration 14 --
252Default Mode:
253Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
254int(1)
255
256COUNT_NORMAL Mode:
257Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
258int(1)
259
260COUNT_RECURSIVE Mode:
261Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
262int(1)
263
264-- Iteration 15 --
265Default Mode:
266Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
267int(1)
268
269COUNT_NORMAL Mode:
270Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
271int(1)
272
273COUNT_RECURSIVE Mode:
274Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
275int(1)
276
277-- Iteration 16 --
278Default Mode:
279Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
280int(1)
281
282COUNT_NORMAL Mode:
283Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
284int(1)
285
286COUNT_RECURSIVE Mode:
287Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
288int(1)
289
290-- Iteration 17 --
291Default Mode:
292Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
293int(1)
294
295COUNT_NORMAL Mode:
296Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
297int(1)
298
299COUNT_RECURSIVE Mode:
300Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
301int(1)
302
303-- Iteration 18 --
304Default Mode:
305Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
306int(0)
307
308COUNT_NORMAL Mode:
309Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
310int(0)
311
312COUNT_RECURSIVE Mode:
313Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
314int(0)
315
316-- Iteration 19 --
317Default Mode:
318Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
319int(1)
320
321COUNT_NORMAL Mode:
322Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
323int(1)
324
325COUNT_RECURSIVE Mode:
326Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d
327int(1)
328
329Done
330