Annotation of embedaddon/php/ext/standard/tests/array/sizeof_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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:
12: echo "*** Testing sizeof() : usage variations ***\n";
13:
14: // get a resource variable
15: $fp = fopen(__FILE__, "r");
16:
17: echo "--- 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;
40: for($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:
60: echo "Done";
61: ?>
62: --EXPECTF--
63: *** Testing sizeof() : usage variations ***
64: --- Testing sizeof() with different array values for 'var' argument ---
65: -- Iteration 1 --
66: Default Mode: int(2)
67:
68: COUNT_NORMAL Mode: int(2)
69:
70: COUNT_RECURSIVE Mode: int(2)
71:
72: -- Iteration 2 --
73: Default Mode: int(2)
74:
75: COUNT_NORMAL Mode: int(2)
76:
77: COUNT_RECURSIVE Mode: int(8)
78:
79: -- Iteration 3 --
80: Default Mode: int(3)
81:
82: COUNT_NORMAL Mode: int(3)
83:
84: COUNT_RECURSIVE Mode: int(6)
85:
86: -- Iteration 4 --
87: Default Mode: int(0)
88:
89: COUNT_NORMAL Mode: int(0)
90:
91: COUNT_RECURSIVE Mode: int(0)
92:
93: -- Iteration 5 --
94: Default Mode: int(4)
95:
96: COUNT_NORMAL Mode: int(4)
97:
98: COUNT_RECURSIVE Mode: int(4)
99:
100: -- Iteration 6 --
101: Default Mode: int(3)
102:
103: COUNT_NORMAL Mode: int(3)
104:
105: COUNT_RECURSIVE Mode: int(3)
106:
107: -- Iteration 7 --
108: Default Mode: int(3)
109:
110: COUNT_NORMAL Mode: int(3)
111:
112: COUNT_RECURSIVE Mode: int(3)
113:
114: -- Iteration 8 --
115: Default Mode: int(2)
116:
117: COUNT_NORMAL Mode: int(2)
118:
119: COUNT_RECURSIVE Mode: int(2)
120:
121: -- Iteration 9 --
122: Default Mode: int(2)
123:
124: COUNT_NORMAL Mode: int(2)
125:
126: COUNT_RECURSIVE Mode: int(2)
127:
128: -- Iteration 10 --
129: Default Mode: int(2)
130:
131: COUNT_NORMAL Mode: int(2)
132:
133: COUNT_RECURSIVE Mode: int(2)
134:
135: -- Iteration 11 --
136: Default Mode: int(2)
137:
138: COUNT_NORMAL Mode: int(2)
139:
140: COUNT_RECURSIVE Mode: int(2)
141:
142: -- Iteration 12 --
143: Default Mode: int(2)
144:
145: COUNT_NORMAL Mode: int(2)
146:
147: COUNT_RECURSIVE Mode: int(2)
148:
149: -- Iteration 13 --
150: Default Mode: int(4)
151:
152: COUNT_NORMAL Mode: int(4)
153:
154: COUNT_RECURSIVE Mode: int(4)
155:
156: -- Iteration 14 --
157: Default Mode: int(4)
158:
159: COUNT_NORMAL Mode: int(4)
160:
161: COUNT_RECURSIVE Mode: int(6)
162:
163: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>