1--TEST--
2Test sizeof() function : usage variations - different array values for 'var' argument
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
14// get a resource variable
15$fp = fopen(__FILE__, "r");
16
17echo "--- Testing sizeof() with different array values for 'var' argument ---\n";
18
19// array containing different types of array values for 'var' argument
20$values = array (
21  /* 1  */  array($fp, "resource" => $fp),
22            array(1, array(3, 4, array(6, array(8)))),
23            array("a" => 1, 'b' => 2, array( "c" =>3, array( "d" => 5))),
24            array(),
25  /* 5  */  array(1, 2, 3, 4),
26            array("Saffron", "White", "Green"),
27            array('saffron', 'white', 'green'),
28            array(1 => "Hi", 2 => "Hello" ),
29            array("color" => "red", "item" => "pen"),
30  /* 10 */  array('color' => 'red', 'item' => 'pen'),
31            array(TRUE => "red", FALSE => "pen" ),
32            array(false => 'red', true => 'pen' ),
33            array('color' => "red", "item" => 'pen', 1 => "Hi", "" => "Hello" ),
34  /* 14 */  array($fp, "resource1" => $fp, 'resource2' => $fp, array( $fp, 'type' => $fp) )
35);
36
37// loop through each element of the values array for 'var' argument
38// check the working of sizeof()
39$counter = 1;
40for($i = 0; $i < count($values); $i++)
41{
42  echo "-- Iteration $counter --\n";
43  $var = $values[$i];
44
45  echo "Default Mode: ";
46  var_dump( sizeof($var) );
47  echo "\n";
48
49  echo "COUNT_NORMAL Mode: ";
50  var_dump( sizeof($var, COUNT_NORMAL) );
51  echo "\n";
52
53  echo "COUNT_RECURSIVE Mode: ";
54  var_dump( sizeof($var, COUNT_RECURSIVE) );
55  echo "\n";
56
57  $counter++;
58}
59
60echo "Done";
61?>
62--EXPECT--
63*** Testing sizeof() : usage variations ***
64--- Testing sizeof() with different array values for 'var' argument ---
65-- Iteration 1 --
66Default Mode: int(2)
67
68COUNT_NORMAL Mode: int(2)
69
70COUNT_RECURSIVE Mode: int(2)
71
72-- Iteration 2 --
73Default Mode: int(2)
74
75COUNT_NORMAL Mode: int(2)
76
77COUNT_RECURSIVE Mode: int(8)
78
79-- Iteration 3 --
80Default Mode: int(3)
81
82COUNT_NORMAL Mode: int(3)
83
84COUNT_RECURSIVE Mode: int(6)
85
86-- Iteration 4 --
87Default Mode: int(0)
88
89COUNT_NORMAL Mode: int(0)
90
91COUNT_RECURSIVE Mode: int(0)
92
93-- Iteration 5 --
94Default Mode: int(4)
95
96COUNT_NORMAL Mode: int(4)
97
98COUNT_RECURSIVE Mode: int(4)
99
100-- Iteration 6 --
101Default Mode: int(3)
102
103COUNT_NORMAL Mode: int(3)
104
105COUNT_RECURSIVE Mode: int(3)
106
107-- Iteration 7 --
108Default Mode: int(3)
109
110COUNT_NORMAL Mode: int(3)
111
112COUNT_RECURSIVE Mode: int(3)
113
114-- Iteration 8 --
115Default Mode: int(2)
116
117COUNT_NORMAL Mode: int(2)
118
119COUNT_RECURSIVE Mode: int(2)
120
121-- Iteration 9 --
122Default Mode: int(2)
123
124COUNT_NORMAL Mode: int(2)
125
126COUNT_RECURSIVE Mode: int(2)
127
128-- Iteration 10 --
129Default Mode: int(2)
130
131COUNT_NORMAL Mode: int(2)
132
133COUNT_RECURSIVE Mode: int(2)
134
135-- Iteration 11 --
136Default Mode: int(2)
137
138COUNT_NORMAL Mode: int(2)
139
140COUNT_RECURSIVE Mode: int(2)
141
142-- Iteration 12 --
143Default Mode: int(2)
144
145COUNT_NORMAL Mode: int(2)
146
147COUNT_RECURSIVE Mode: int(2)
148
149-- Iteration 13 --
150Default Mode: int(4)
151
152COUNT_NORMAL Mode: int(4)
153
154COUNT_RECURSIVE Mode: int(4)
155
156-- Iteration 14 --
157Default Mode: int(4)
158
159COUNT_NORMAL Mode: int(4)
160
161COUNT_RECURSIVE Mode: int(6)
162
163Done
164