1--TEST--
2Test str_split() function : usage variations - unexpected values for 'split_length' argument
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit 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 %s on line %d
111bool(false)
112--Iteration 3 --
113array(1) {
114  [0]=>
115  string(23) "variation2:split_length"
116}
117--Iteration 4 --
118
119Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
120bool(false)
121--Iteration 5 --
122
123Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
124bool(false)
125--Iteration 6 --
126
127Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
128NULL
129--Iteration 7 --
130
131Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
132NULL
133--Iteration 8 --
134
135Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
136NULL
137--Iteration 9 --
138
139Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
140NULL
141--Iteration 10 --
142
143Warning: str_split() expects parameter 2 to be long, array given in %s on line %d
144NULL
145--Iteration 11 --
146
147Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
148bool(false)
149--Iteration 12 --
150
151Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
152bool(false)
153--Iteration 13 --
154array(23) {
155  [0]=>
156  string(1) "v"
157  [1]=>
158  string(1) "a"
159  [2]=>
160  string(1) "r"
161  [3]=>
162  string(1) "i"
163  [4]=>
164  string(1) "a"
165  [5]=>
166  string(1) "t"
167  [6]=>
168  string(1) "i"
169  [7]=>
170  string(1) "o"
171  [8]=>
172  string(1) "n"
173  [9]=>
174  string(1) "2"
175  [10]=>
176  string(1) ":"
177  [11]=>
178  string(1) "s"
179  [12]=>
180  string(1) "p"
181  [13]=>
182  string(1) "l"
183  [14]=>
184  string(1) "i"
185  [15]=>
186  string(1) "t"
187  [16]=>
188  string(1) "_"
189  [17]=>
190  string(1) "l"
191  [18]=>
192  string(1) "e"
193  [19]=>
194  string(1) "n"
195  [20]=>
196  string(1) "g"
197  [21]=>
198  string(1) "t"
199  [22]=>
200  string(1) "h"
201}
202--Iteration 14 --
203
204Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
205bool(false)
206--Iteration 15 --
207array(23) {
208  [0]=>
209  string(1) "v"
210  [1]=>
211  string(1) "a"
212  [2]=>
213  string(1) "r"
214  [3]=>
215  string(1) "i"
216  [4]=>
217  string(1) "a"
218  [5]=>
219  string(1) "t"
220  [6]=>
221  string(1) "i"
222  [7]=>
223  string(1) "o"
224  [8]=>
225  string(1) "n"
226  [9]=>
227  string(1) "2"
228  [10]=>
229  string(1) ":"
230  [11]=>
231  string(1) "s"
232  [12]=>
233  string(1) "p"
234  [13]=>
235  string(1) "l"
236  [14]=>
237  string(1) "i"
238  [15]=>
239  string(1) "t"
240  [16]=>
241  string(1) "_"
242  [17]=>
243  string(1) "l"
244  [18]=>
245  string(1) "e"
246  [19]=>
247  string(1) "n"
248  [20]=>
249  string(1) "g"
250  [21]=>
251  string(1) "t"
252  [22]=>
253  string(1) "h"
254}
255--Iteration 16 --
256
257Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
258bool(false)
259--Iteration 17 --
260
261Warning: str_split() expects parameter 2 to be long, string given in %s on line %d
262NULL
263--Iteration 18 --
264
265Warning: str_split() expects parameter 2 to be long, string given in %s on line %d
266NULL
267--Iteration 19 --
268
269Warning: str_split() expects parameter 2 to be long, string given in %s on line %d
270NULL
271--Iteration 20 --
272
273Warning: str_split() expects parameter 2 to be long, string given in %s on line %d
274NULL
275--Iteration 21 --
276
277Warning: str_split() expects parameter 2 to be long, object given in %s on line %d
278NULL
279--Iteration 22 --
280
281Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
282bool(false)
283--Iteration 23 --
284
285Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
286bool(false)
287--Iteration 24 --
288
289Warning: str_split() expects parameter 2 to be long, resource given in %s on line %d
290NULL
291Done
292