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: int(1)
84
85COUNT_NORMAL Mode: int(1)
86
87COUNT_RECURSIVE Mode: int(1)
88
89-- Iteration 2 --
90Default Mode: int(1)
91
92COUNT_NORMAL Mode: int(1)
93
94COUNT_RECURSIVE Mode: int(1)
95
96-- Iteration 3 --
97Default Mode: int(1)
98
99COUNT_NORMAL Mode: int(1)
100
101COUNT_RECURSIVE Mode: int(1)
102
103-- Iteration 4 --
104Default Mode: int(1)
105
106COUNT_NORMAL Mode: int(1)
107
108COUNT_RECURSIVE Mode: int(1)
109
110-- Iteration 5 --
111Default Mode: int(1)
112
113COUNT_NORMAL Mode: int(1)
114
115COUNT_RECURSIVE Mode: int(1)
116
117-- Iteration 6 --
118Default Mode: int(1)
119
120COUNT_NORMAL Mode: int(1)
121
122COUNT_RECURSIVE Mode: int(1)
123
124-- Iteration 7 --
125Default Mode: int(1)
126
127COUNT_NORMAL Mode: int(1)
128
129COUNT_RECURSIVE Mode: int(1)
130
131-- Iteration 8 --
132Default Mode: int(0)
133
134COUNT_NORMAL Mode: int(0)
135
136COUNT_RECURSIVE Mode: int(0)
137
138-- Iteration 9 --
139Default Mode: int(0)
140
141COUNT_NORMAL Mode: int(0)
142
143COUNT_RECURSIVE Mode: int(0)
144
145-- Iteration 10 --
146Default Mode: int(1)
147
148COUNT_NORMAL Mode: int(1)
149
150COUNT_RECURSIVE Mode: int(1)
151
152-- Iteration 11 --
153Default Mode: int(1)
154
155COUNT_NORMAL Mode: int(1)
156
157COUNT_RECURSIVE Mode: int(1)
158
159-- Iteration 12 --
160Default Mode: int(1)
161
162COUNT_NORMAL Mode: int(1)
163
164COUNT_RECURSIVE Mode: int(1)
165
166-- Iteration 13 --
167Default Mode: int(1)
168
169COUNT_NORMAL Mode: int(1)
170
171COUNT_RECURSIVE Mode: int(1)
172
173-- Iteration 14 --
174Default Mode: int(1)
175
176COUNT_NORMAL Mode: int(1)
177
178COUNT_RECURSIVE Mode: int(1)
179
180-- Iteration 15 --
181Default Mode: int(1)
182
183COUNT_NORMAL Mode: int(1)
184
185COUNT_RECURSIVE Mode: int(1)
186
187-- Iteration 16 --
188Default Mode: int(1)
189
190COUNT_NORMAL Mode: int(1)
191
192COUNT_RECURSIVE Mode: int(1)
193
194-- Iteration 17 --
195Default Mode: int(1)
196
197COUNT_NORMAL Mode: int(1)
198
199COUNT_RECURSIVE Mode: int(1)
200
201-- Iteration 18 --
202Default Mode: int(0)
203
204COUNT_NORMAL Mode: int(0)
205
206COUNT_RECURSIVE Mode: int(0)
207
208-- Iteration 19 --
209Default Mode: int(1)
210
211COUNT_NORMAL Mode: int(1)
212
213COUNT_RECURSIVE Mode: int(1)
214
215Done
216