1--TEST--
2Test str_split() function : usage variations - unexpected values for 'split_length' argument
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
6?>
7--FILE--
8<?php
9/* Prototype  : array str_split(string $str [, int $split_length])
10 * Description: Convert a string to an array. If split_length is
11                specified, break the string down into chunks each
12                split_length characters long.
13 * Source code: ext/standard/string.c
14 * Alias to functions: none
15*/
16
17echo "*** Testing str_split() : unexpected values for 'split_length' ***\n";
18
19// Initialise function arguments
20$str = 'variation2:split_length';
21
22//get an unset variable
23$unset_var = 10;
24unset ($unset_var);
25
26//defining class for object variable
27class MyClass
28{
29  public function __toString()
30  {
31    return "object";
32  }
33}
34
35//resource variable
36$fp = fopen(__FILE__, 'r');
37
38//different values for 'split_length'
39$values = array(
40
41  // float data
42  10.5,
43  -10.5,
44  10.6E10,
45  10.6E-10,
46  .5,
47
48  // array data
49  array(),
50  array(0),
51  array(1),
52  array(1, 2),
53  array('color' => 'red', 'item' => 'pen'),
54
55  // null data
56  NULL,
57  null,
58
59  // boolean data
60  true,
61  false,
62  TRUE,
63  FALSE,
64
65  // empty data
66  "",
67  '',
68
69  // string data
70  "string",
71  'string',
72
73  // object data
74  new MyClass(),
75
76  // undefined data
77  @$undefined_var,
78
79  // unset data
80  @$unset_var,
81
82  //resource data
83  $fp
84);
85
86// loop through each element of $values for 'split_length'
87for($count = 0; $count < count($values); $count++) {
88  echo "--Iteration ".($count+1)." --\n";
89  var_dump( str_split($str, $values[$count]) );
90}
91
92//closing resource
93fclose($fp);
94
95echo "Done";
96?>
97--EXPECTF--
98*** Testing str_split() : unexpected values for 'split_length' ***
99--Iteration 1 --
100array(3) {
101  [0]=>
102  string(10) "variation2"
103  [1]=>
104  string(10) ":split_len"
105  [2]=>
106  string(3) "gth"
107}
108--Iteration 2 --
109
110Warning: str_split(): The length of each segment must be greater than zero in %sstr_split_variation2.php on line %d
111bool(false)
112--Iteration 3 --
113
114Warning: str_split() expects parameter 2 to be integer, float given in %s on line %d
115NULL
116--Iteration 4 --
117
118Warning: str_split(): The length of each segment must be greater than zero in %sstr_split_variation2.php on line %d
119bool(false)
120--Iteration 5 --
121
122Warning: str_split(): The length of each segment must be greater than zero in %sstr_split_variation2.php on line %d
123bool(false)
124--Iteration 6 --
125
126Warning: str_split() expects parameter 2 to be integer, array given in %sstr_split_variation2.php on line %d
127NULL
128--Iteration 7 --
129
130Warning: str_split() expects parameter 2 to be integer, array given in %sstr_split_variation2.php on line %d
131NULL
132--Iteration 8 --
133
134Warning: str_split() expects parameter 2 to be integer, array given in %sstr_split_variation2.php on line %d
135NULL
136--Iteration 9 --
137
138Warning: str_split() expects parameter 2 to be integer, array given in %sstr_split_variation2.php on line %d
139NULL
140--Iteration 10 --
141
142Warning: str_split() expects parameter 2 to be integer, array given in %sstr_split_variation2.php on line %d
143NULL
144--Iteration 11 --
145
146Warning: str_split(): The length of each segment must be greater than zero in %sstr_split_variation2.php on line %d
147bool(false)
148--Iteration 12 --
149
150Warning: str_split(): The length of each segment must be greater than zero in %sstr_split_variation2.php on line %d
151bool(false)
152--Iteration 13 --
153array(23) {
154  [0]=>
155  string(1) "v"
156  [1]=>
157  string(1) "a"
158  [2]=>
159  string(1) "r"
160  [3]=>
161  string(1) "i"
162  [4]=>
163  string(1) "a"
164  [5]=>
165  string(1) "t"
166  [6]=>
167  string(1) "i"
168  [7]=>
169  string(1) "o"
170  [8]=>
171  string(1) "n"
172  [9]=>
173  string(1) "2"
174  [10]=>
175  string(1) ":"
176  [11]=>
177  string(1) "s"
178  [12]=>
179  string(1) "p"
180  [13]=>
181  string(1) "l"
182  [14]=>
183  string(1) "i"
184  [15]=>
185  string(1) "t"
186  [16]=>
187  string(1) "_"
188  [17]=>
189  string(1) "l"
190  [18]=>
191  string(1) "e"
192  [19]=>
193  string(1) "n"
194  [20]=>
195  string(1) "g"
196  [21]=>
197  string(1) "t"
198  [22]=>
199  string(1) "h"
200}
201--Iteration 14 --
202
203Warning: str_split(): The length of each segment must be greater than zero in %sstr_split_variation2.php on line %d
204bool(false)
205--Iteration 15 --
206array(23) {
207  [0]=>
208  string(1) "v"
209  [1]=>
210  string(1) "a"
211  [2]=>
212  string(1) "r"
213  [3]=>
214  string(1) "i"
215  [4]=>
216  string(1) "a"
217  [5]=>
218  string(1) "t"
219  [6]=>
220  string(1) "i"
221  [7]=>
222  string(1) "o"
223  [8]=>
224  string(1) "n"
225  [9]=>
226  string(1) "2"
227  [10]=>
228  string(1) ":"
229  [11]=>
230  string(1) "s"
231  [12]=>
232  string(1) "p"
233  [13]=>
234  string(1) "l"
235  [14]=>
236  string(1) "i"
237  [15]=>
238  string(1) "t"
239  [16]=>
240  string(1) "_"
241  [17]=>
242  string(1) "l"
243  [18]=>
244  string(1) "e"
245  [19]=>
246  string(1) "n"
247  [20]=>
248  string(1) "g"
249  [21]=>
250  string(1) "t"
251  [22]=>
252  string(1) "h"
253}
254--Iteration 16 --
255
256Warning: str_split(): The length of each segment must be greater than zero in %sstr_split_variation2.php on line %d
257bool(false)
258--Iteration 17 --
259
260Warning: str_split() expects parameter 2 to be integer, string given in %sstr_split_variation2.php on line %d
261NULL
262--Iteration 18 --
263
264Warning: str_split() expects parameter 2 to be integer, string given in %sstr_split_variation2.php on line %d
265NULL
266--Iteration 19 --
267
268Warning: str_split() expects parameter 2 to be integer, string given in %sstr_split_variation2.php on line %d
269NULL
270--Iteration 20 --
271
272Warning: str_split() expects parameter 2 to be integer, string given in %sstr_split_variation2.php on line %d
273NULL
274--Iteration 21 --
275
276Warning: str_split() expects parameter 2 to be integer, object given in %sstr_split_variation2.php on line %d
277NULL
278--Iteration 22 --
279
280Warning: str_split(): The length of each segment must be greater than zero in %sstr_split_variation2.php on line %d
281bool(false)
282--Iteration 23 --
283
284Warning: str_split(): The length of each segment must be greater than zero in %sstr_split_variation2.php on line %d
285bool(false)
286--Iteration 24 --
287
288Warning: str_split() expects parameter 2 to be integer, resource given in %sstr_split_variation2.php on line %d
289NULL
290Done
291