Annotation of embedaddon/php/ext/standard/tests/array/count_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test count() function : usage variations - Pass different data types as $var arg
3: --FILE--
4: <?php
5: /* Prototype : int count(mixed $var [, int $mode])
6: * Description: Count the number of elements in a variable (usually an array)
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * aPass different data types as $var argument to count() to test behaviour
12: */
13:
14: echo "*** Testing count() : usage variations ***\n";
15:
16: //get an unset variable
17: $unset_var = 10;
18: unset ($unset_var);
19:
20: // get a class
21: class classA
22: {
23: public function __toString() {
24: return "Class A object";
25: }
26: }
27:
28: // heredoc string
29: $heredoc = <<<EOT
30: hello world
31: EOT;
32:
33: // get a resource variable
34: $fp = fopen(__FILE__, "r");
35:
36: // unexpected values to be passed to $var argument
37: $inputs = array(
38:
39: // int data
40: /*1*/ 0,
41: 1,
42: 12345,
43: -2345,
44:
45: // float data
46: /*5*/ 10.5,
47: -10.5,
48: 12.3456789000e10,
49: 12.3456789000E-10,
50: .5,
51:
52: // null data
53: /*10*/ NULL,
54: null,
55:
56: // boolean data
57: /*12*/ true,
58: false,
59: TRUE,
60: FALSE,
61:
62: // empty data
63: /*16*/ "",
64: '',
65:
66: // string data
67: /*18*/ "string",
68: 'string',
69: $heredoc,
70:
71: // object data
72: /*21*/ new classA(),
73:
74: // undefined data
75: /*22*/ @$undefined_var,
76:
77: // unset data
78: /*23*/ @$unset_var,
79:
80: // resource variable
81: /*24*/ $fp
82: );
83:
84: // loop through each element of $inputs to check the behavior of count()
85: $iterator = 1;
86: foreach($inputs as $input) {
87: echo "\n-- Iteration $iterator --\n";
88: var_dump( count($input) );
89: $iterator++;
90: };
91:
92: fclose($fp);
93:
94: echo "Done";
95: ?>
96: --EXPECTF--
97: *** Testing count() : usage variations ***
98:
99: -- Iteration 1 --
100: int(1)
101:
102: -- Iteration 2 --
103: int(1)
104:
105: -- Iteration 3 --
106: int(1)
107:
108: -- Iteration 4 --
109: int(1)
110:
111: -- Iteration 5 --
112: int(1)
113:
114: -- Iteration 6 --
115: int(1)
116:
117: -- Iteration 7 --
118: int(1)
119:
120: -- Iteration 8 --
121: int(1)
122:
123: -- Iteration 9 --
124: int(1)
125:
126: -- Iteration 10 --
127: int(0)
128:
129: -- Iteration 11 --
130: int(0)
131:
132: -- Iteration 12 --
133: int(1)
134:
135: -- Iteration 13 --
136: int(1)
137:
138: -- Iteration 14 --
139: int(1)
140:
141: -- Iteration 15 --
142: int(1)
143:
144: -- Iteration 16 --
145: int(1)
146:
147: -- Iteration 17 --
148: int(1)
149:
150: -- Iteration 18 --
151: int(1)
152:
153: -- Iteration 19 --
154: int(1)
155:
156: -- Iteration 20 --
157: int(1)
158:
159: -- Iteration 21 --
160: int(1)
161:
162: -- Iteration 22 --
163: int(0)
164:
165: -- Iteration 23 --
166: int(0)
167:
168: -- Iteration 24 --
169: int(1)
170: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>