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