1--TEST--
2Test mb_split() function : usage variations  - different parameter types for string
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");
7?>
8--FILE--
9<?php
10/* Prototype  : proto array mb_split(string pattern, string string [, int limit])
11 * Description: split multibyte string into array by regular expression
12 * Source code: ext/mbstring/php_mbregex.c
13 * Alias to functions:
14 */
15
16
17echo "*** Testing mb_split() : usage variations ***\n";
18
19// Initialise function arguments not being substituted (if any)
20$pattern = '[a-z]';
21$limit = 10;
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, $input, $limit) );
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(1) "0"
110}
111
112-- Iteration 2 --
113array(1) {
114  [0]=>
115  string(1) "1"
116}
117
118-- Iteration 3 --
119array(1) {
120  [0]=>
121  string(5) "12345"
122}
123
124-- Iteration 4 --
125array(1) {
126  [0]=>
127  string(5) "-2345"
128}
129
130-- Iteration 5 --
131array(1) {
132  [0]=>
133  string(4) "10.5"
134}
135
136-- Iteration 6 --
137array(1) {
138  [0]=>
139  string(5) "-10.5"
140}
141
142-- Iteration 7 --
143array(1) {
144  [0]=>
145  string(12) "123456789000"
146}
147
148-- Iteration 8 --
149array(1) {
150  [0]=>
151  string(13) "1.23456789E-9"
152}
153
154-- Iteration 9 --
155array(1) {
156  [0]=>
157  string(3) "0.5"
158}
159
160-- Iteration 10 --
161array(1) {
162  [0]=>
163  string(0) ""
164}
165
166-- Iteration 11 --
167array(1) {
168  [0]=>
169  string(0) ""
170}
171
172-- Iteration 12 --
173array(1) {
174  [0]=>
175  string(1) "1"
176}
177
178-- Iteration 13 --
179array(1) {
180  [0]=>
181  string(0) ""
182}
183
184-- Iteration 14 --
185array(1) {
186  [0]=>
187  string(1) "1"
188}
189
190-- Iteration 15 --
191array(1) {
192  [0]=>
193  string(0) ""
194}
195
196-- Iteration 16 --
197array(1) {
198  [0]=>
199  string(0) ""
200}
201
202-- Iteration 17 --
203array(1) {
204  [0]=>
205  string(0) ""
206}
207
208-- Iteration 18 --
209array(1) {
210  [0]=>
211  string(5) "UTF-8"
212}
213
214-- Iteration 19 --
215array(1) {
216  [0]=>
217  string(5) "UTF-8"
218}
219
220-- Iteration 20 --
221array(1) {
222  [0]=>
223  string(5) "UTF-8"
224}
225
226-- Iteration 21 --
227array(1) {
228  [0]=>
229  string(5) "UTF-8"
230}
231
232-- Iteration 22 --
233array(1) {
234  [0]=>
235  string(0) ""
236}
237
238-- Iteration 23 --
239array(1) {
240  [0]=>
241  string(0) ""
242}
243
244-- Iteration 24 --
245
246Warning: mb_split() expects parameter 2 to be string, resource given in %s on line %d
247bool(false)
248Done
249