1--TEST--
2Test sizeof() function : usage variations - different values for 'mode' 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
14echo "--- Testing sizeof() with different values for 'mode' argument ---\n";
15$array1 = array(1, 2, 3, 4, array(1.0, 2.0, array()), array() );
16
17// get a resource variable
18$fp = fopen(__FILE__, "r");
19
20//unset variable
21$unset_var = 10;
22unset($unset_var);
23
24//class declaration
25class test
26{
27  public $member1;
28}
29
30$mode_values = array (
31  /* 1  */  COUNT_NORMAL,
32            COUNT_RECURSIVE,
33            0,  // same as COUNT_NORMAL
34            1,  // same as COUNT_RECURSIVE
35
36  /* 5  */  TRUE,  // same as COUNT_RECURSIVE
37            true,  // same as COUNT_RECURSIVE
38            FALSE, // same as COUNT_NORMAL
39            false, // same as COUNT_NORMAL
40            NULL,  // same as COUNT_NORMAL
41  /* 10 */  null,  // same as COUNT_NORMAL
42            100,
43            10.5,
44            12.34e3,
45            12.34E-2,
46  /* 15 */  .5,
47            "",
48            '',
49            "string",
50            'string',
51  /* 20 */  @$unset_var,
52            new test(),
53  /* 22 */  $fp
54);
55
56// loop through the each element of $modes_array for 'mode' argument
57// and check the working of sizeof()
58$counter = 1;
59for($i = 0; $i < count($mode_values); $i++)
60{
61  echo "-- Iteration $counter --\n";
62  $mode = $mode_values[$i];
63
64  var_dump( sizeof($array1, $mode) );
65
66  $counter++;
67}
68
69fclose($fp);
70
71echo "Done";
72?>
73--EXPECTF--
74*** Testing sizeof() : usage variations ***
75--- Testing sizeof() with different values for 'mode' argument ---
76-- Iteration 1 --
77int(6)
78-- Iteration 2 --
79int(9)
80-- Iteration 3 --
81int(6)
82-- Iteration 4 --
83int(9)
84-- Iteration 5 --
85int(9)
86-- Iteration 6 --
87int(9)
88-- Iteration 7 --
89int(6)
90-- Iteration 8 --
91int(6)
92-- Iteration 9 --
93int(6)
94-- Iteration 10 --
95int(6)
96-- Iteration 11 --
97int(6)
98-- Iteration 12 --
99int(6)
100-- Iteration 13 --
101int(6)
102-- Iteration 14 --
103int(6)
104-- Iteration 15 --
105int(6)
106-- Iteration 16 --
107
108Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d
109NULL
110-- Iteration 17 --
111
112Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d
113NULL
114-- Iteration 18 --
115
116Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d
117NULL
118-- Iteration 19 --
119
120Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d
121NULL
122-- Iteration 20 --
123int(6)
124-- Iteration 21 --
125
126Warning: sizeof() expects parameter 2 to be long, object given in %s on line %d
127NULL
128-- Iteration 22 --
129
130Warning: sizeof() expects parameter 2 to be long, resource given in %s on line %d
131NULL
132Done
133