1--TEST--
2Test count_chars() function : usage variations - test values for $mode argument
3--FILE--
4<?php
5
6/* Prototype  : mixed count_chars  ( string $string  [, int $mode  ] )
7 * Description: Return information about characters used in a string
8 * Source code: ext/standard/string.c
9*/
10
11echo "*** Testing count_chars() function: with unexpected inputs for 'mode' argument ***\n";
12
13//get an unset variable
14$unset_var = 'string_val';
15unset($unset_var);
16
17//defining a class
18class sample  {
19}
20
21// array with different values for $input
22$inputs =  array (
23
24			  // integer values
25/* 1 */		  0,
26			  1,
27			  255,
28			  2147483647,
29		      -2147483648,
30
31			  // float values
32/* 6 */		  0.0,
33			  1.3,
34			  10.5,
35			  -20.5,
36			  10.1234567e10,
37
38			  // array values
39/* 11 */	  array(),
40			  array(1, 2, 3, 4, 5, 6, 7, 8, 9),
41
42			  // boolean values
43/* 14 */	  true,
44			  false,
45			  TRUE,
46			  FALSE,
47
48			  // null values
49/* 18 */	  NULL,
50			  null,
51
52			  // string values
53/* 20 */	  "ABCD",
54			  'abcd',
55			  "1ABC",
56			  "5ABC",
57
58			  // objects
59/* 24 */ 	  new sample(),
60
61			   // undefined variable
62/* 25 */	  @$undefined_var,
63
64			  // unset variable
65/* 26 */	  @$unset_var
66);
67
68// loop through with each element of the $inputs array to test count_chars() function
69// with unexepcted values for the 'mode' argument
70$count = 1;
71$string = "Return information about characters used in a string";
72foreach($inputs as $input) {
73  echo "-- Iteration $count --\n";
74  // only list characters with a frequency > 0
75  var_dump(is_array(count_chars($string, $input)));
76  $count ++;
77}
78
79
80?>
81===DONE===
82--EXPECTF--
83*** Testing count_chars() function: with unexpected inputs for 'mode' argument ***
84-- Iteration 1 --
85bool(true)
86-- Iteration 2 --
87bool(true)
88-- Iteration 3 --
89
90Warning: count_chars(): Unknown mode in %s on line %d
91bool(false)
92-- Iteration 4 --
93
94Warning: count_chars(): Unknown mode in %s on line %d
95bool(false)
96-- Iteration 5 --
97
98Warning: count_chars(): Unknown mode in %s on line %d
99bool(false)
100-- Iteration 6 --
101bool(true)
102-- Iteration 7 --
103bool(true)
104-- Iteration 8 --
105
106Warning: count_chars(): Unknown mode in %s on line %d
107bool(false)
108-- Iteration 9 --
109
110Warning: count_chars(): Unknown mode in %s on line %d
111bool(false)
112-- Iteration 10 --
113
114Warning: count_chars(): Unknown mode in %s on line %d
115bool(false)
116-- Iteration 11 --
117
118Warning: count_chars() expects parameter 2 to be long, array given in %s on line %d
119bool(false)
120-- Iteration 12 --
121
122Warning: count_chars() expects parameter 2 to be long, array given in %s on line %d
123bool(false)
124-- Iteration 13 --
125bool(true)
126-- Iteration 14 --
127bool(true)
128-- Iteration 15 --
129bool(true)
130-- Iteration 16 --
131bool(true)
132-- Iteration 17 --
133bool(true)
134-- Iteration 18 --
135bool(true)
136-- Iteration 19 --
137
138Warning: count_chars() expects parameter 2 to be long, string given in %s on line %d
139bool(false)
140-- Iteration 20 --
141
142Warning: count_chars() expects parameter 2 to be long, string given in %s on line %d
143bool(false)
144-- Iteration 21 --
145
146Notice: A non well formed numeric value encountered in %s on line %d
147bool(true)
148-- Iteration 22 --
149
150Notice: A non well formed numeric value encountered in %s on line %d
151
152Warning: count_chars(): Unknown mode in %s on line %d
153bool(false)
154-- Iteration 23 --
155
156Warning: count_chars() expects parameter 2 to be long, object given in %s on line %d
157bool(false)
158-- Iteration 24 --
159bool(true)
160-- Iteration 25 --
161bool(true)
162===DONE===
163