1--TEST--
2Test mb_split() function : usage variations  - different parameter types for limit
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_split') or die("skip mb_split() is not available in this build");
7if (PHP_INT_SIZE != 8) die('skip 64-bit only');
8?>
9--FILE--
10<?php
11/* Prototype  : proto array mb_split(string pattern, string string [, int limit])
12 * Description: split multibyte string into array by regular expression
13 * Source code: ext/mbstring/php_mbregex.c
14 * Alias to functions:
15 */
16
17echo "*** Testing mb_split() : usage variations ***\n";
18
19// Initialise function arguments not being substituted (if any)
20$pattern = '[a-z]';
21$string = 'string_val';
22
23//get an unset variable
24$unset_var = 10;
25unset ($unset_var);
26
27// get a class
28class classA
29{
30  public function __toString() {
31    return "UTF-8";
32  }
33}
34
35// heredoc string
36$heredoc = <<<EOT
37UTF-8
38EOT;
39
40// get a resource variable
41$fp = fopen(__FILE__, "r");
42
43// unexpected values to be passed to $encoding argument
44$inputs = array(
45
46       // int data
47/*1*/  0,
48       1,
49       12345,
50       -2345,
51
52       // float data
53/*5*/  10.5,
54       -10.5,
55       12.3456789000e10,
56       12.3456789000E-10,
57       .5,
58
59       // null data
60/*10*/ NULL,
61       null,
62
63       // boolean data
64/*12*/ true,
65       false,
66       TRUE,
67       FALSE,
68
69       // empty data
70/*16*/ "",
71       '',
72
73       // string data
74/*18*/ "UTF-8",
75       'UTF-8',
76       $heredoc,
77
78       // object data
79/*21*/ new classA(),
80
81       // undefined data
82/*22*/ @$undefined_var,
83
84       // unset data
85/*23*/ @$unset_var,
86
87       // resource variable
88/*24*/ $fp
89);
90
91// loop through each element of the array for pattern
92
93$iterator = 1;
94foreach($inputs as $input) {
95      echo "\n-- Iteration $iterator --\n";
96      var_dump( mb_split($pattern, $string, $input) );
97      $iterator++;
98};
99
100fclose($fp);
101echo "Done";
102?>
103--EXPECTF--
104*** Testing mb_split() : usage variations ***
105
106-- Iteration 1 --
107array(1) {
108  [0]=>
109  string(10) "string_val"
110}
111
112-- Iteration 2 --
113array(1) {
114  [0]=>
115  string(10) "string_val"
116}
117
118-- Iteration 3 --
119array(10) {
120  [0]=>
121  string(0) ""
122  [1]=>
123  string(0) ""
124  [2]=>
125  string(0) ""
126  [3]=>
127  string(0) ""
128  [4]=>
129  string(0) ""
130  [5]=>
131  string(0) ""
132  [6]=>
133  string(1) "_"
134  [7]=>
135  string(0) ""
136  [8]=>
137  string(0) ""
138  [9]=>
139  string(0) ""
140}
141
142-- Iteration 4 --
143array(10) {
144  [0]=>
145  string(0) ""
146  [1]=>
147  string(0) ""
148  [2]=>
149  string(0) ""
150  [3]=>
151  string(0) ""
152  [4]=>
153  string(0) ""
154  [5]=>
155  string(0) ""
156  [6]=>
157  string(1) "_"
158  [7]=>
159  string(0) ""
160  [8]=>
161  string(0) ""
162  [9]=>
163  string(0) ""
164}
165
166-- Iteration 5 --
167array(10) {
168  [0]=>
169  string(0) ""
170  [1]=>
171  string(0) ""
172  [2]=>
173  string(0) ""
174  [3]=>
175  string(0) ""
176  [4]=>
177  string(0) ""
178  [5]=>
179  string(0) ""
180  [6]=>
181  string(1) "_"
182  [7]=>
183  string(0) ""
184  [8]=>
185  string(0) ""
186  [9]=>
187  string(0) ""
188}
189
190-- Iteration 6 --
191array(10) {
192  [0]=>
193  string(0) ""
194  [1]=>
195  string(0) ""
196  [2]=>
197  string(0) ""
198  [3]=>
199  string(0) ""
200  [4]=>
201  string(0) ""
202  [5]=>
203  string(0) ""
204  [6]=>
205  string(1) "_"
206  [7]=>
207  string(0) ""
208  [8]=>
209  string(0) ""
210  [9]=>
211  string(0) ""
212}
213
214-- Iteration 7 --
215array(10) {
216  [0]=>
217  string(0) ""
218  [1]=>
219  string(0) ""
220  [2]=>
221  string(0) ""
222  [3]=>
223  string(0) ""
224  [4]=>
225  string(0) ""
226  [5]=>
227  string(0) ""
228  [6]=>
229  string(1) "_"
230  [7]=>
231  string(0) ""
232  [8]=>
233  string(0) ""
234  [9]=>
235  string(0) ""
236}
237
238-- Iteration 8 --
239array(1) {
240  [0]=>
241  string(10) "string_val"
242}
243
244-- Iteration 9 --
245array(1) {
246  [0]=>
247  string(10) "string_val"
248}
249
250-- Iteration 10 --
251array(1) {
252  [0]=>
253  string(10) "string_val"
254}
255
256-- Iteration 11 --
257array(1) {
258  [0]=>
259  string(10) "string_val"
260}
261
262-- Iteration 12 --
263array(1) {
264  [0]=>
265  string(10) "string_val"
266}
267
268-- Iteration 13 --
269array(1) {
270  [0]=>
271  string(10) "string_val"
272}
273
274-- Iteration 14 --
275array(1) {
276  [0]=>
277  string(10) "string_val"
278}
279
280-- Iteration 15 --
281array(1) {
282  [0]=>
283  string(10) "string_val"
284}
285
286-- Iteration 16 --
287
288Warning: mb_split() expects parameter 3 to be int, string given in %s on line %d
289bool(false)
290
291-- Iteration 17 --
292
293Warning: mb_split() expects parameter 3 to be int, string given in %s on line %d
294bool(false)
295
296-- Iteration 18 --
297
298Warning: mb_split() expects parameter 3 to be int, string given in %s on line %d
299bool(false)
300
301-- Iteration 19 --
302
303Warning: mb_split() expects parameter 3 to be int, string given in %s on line %d
304bool(false)
305
306-- Iteration 20 --
307
308Warning: mb_split() expects parameter 3 to be int, string given in %s on line %d
309bool(false)
310
311-- Iteration 21 --
312
313Warning: mb_split() expects parameter 3 to be int, object given in %s on line %d
314bool(false)
315
316-- Iteration 22 --
317array(1) {
318  [0]=>
319  string(10) "string_val"
320}
321
322-- Iteration 23 --
323array(1) {
324  [0]=>
325  string(10) "string_val"
326}
327
328-- Iteration 24 --
329
330Warning: mb_split() expects parameter 3 to be int, resource given in %s on line %d
331bool(false)
332Done
333