1--TEST--
2Test mb_split() function : usage variations  - different parameter types for pattern
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
16echo "*** Testing mb_split() : usage variations ***\n";
17
18// Initialise function arguments not being substituted (if any)
19$string = 'a b c d e f g';
20$limit = 10;
21
22//get an unset variable
23$unset_var = 10;
24unset ($unset_var);
25
26// get a class
27class classA
28{
29  public function __toString() {
30    return "UTF-8";
31  }
32}
33
34// heredoc string
35$heredoc = <<<EOT
36UTF-8
37EOT;
38
39// get a resource variable
40$fp = fopen(__FILE__, "r");
41
42// unexpected values to be passed to $encoding argument
43$inputs = array(
44
45       // int data
46/*1*/  0,
47       1,
48       12345,
49       -2345,
50
51       // float data
52/*5*/  10.5,
53       -10.5,
54       12.3456789000e10,
55       12.3456789000E-10,
56       .5,
57
58       // null data
59/*10*/ NULL,
60       null,
61
62       // boolean data
63/*12*/ true,
64       false,
65       TRUE,
66       FALSE,
67
68       // empty data
69/*16*/ "",
70       '',
71
72       // string data
73/*18*/ "UTF-8",
74       'UTF-8',
75       $heredoc,
76
77       // object data
78/*21*/ new classA(),
79
80       // undefined data
81/*22*/ @$undefined_var,
82
83       // unset data
84/*23*/ @$unset_var,
85
86       // resource variable
87/*24*/ $fp
88);
89
90// loop through each element of the array for pattern
91
92$iterator = 1;
93foreach($inputs as $input) {
94      echo "\n-- Iteration $iterator --\n";
95      var_dump( mb_split($input, $string, $limit) );
96      $iterator++;
97};
98fclose($fp);
99echo "Done";
100?>
101--EXPECTF--
102*** Testing mb_split() : usage variations ***
103
104-- Iteration 1 --
105array(1) {
106  [0]=>
107  string(13) "a b c d e f g"
108}
109
110-- Iteration 2 --
111array(1) {
112  [0]=>
113  string(13) "a b c d e f g"
114}
115
116-- Iteration 3 --
117array(1) {
118  [0]=>
119  string(13) "a b c d e f g"
120}
121
122-- Iteration 4 --
123array(1) {
124  [0]=>
125  string(13) "a b c d e f g"
126}
127
128-- Iteration 5 --
129array(1) {
130  [0]=>
131  string(13) "a b c d e f g"
132}
133
134-- Iteration 6 --
135array(1) {
136  [0]=>
137  string(13) "a b c d e f g"
138}
139
140-- Iteration 7 --
141array(1) {
142  [0]=>
143  string(13) "a b c d e f g"
144}
145
146-- Iteration 8 --
147array(1) {
148  [0]=>
149  string(13) "a b c d e f g"
150}
151
152-- Iteration 9 --
153array(1) {
154  [0]=>
155  string(13) "a b c d e f g"
156}
157
158-- Iteration 10 --
159array(1) {
160  [0]=>
161  string(13) "a b c d e f g"
162}
163
164-- Iteration 11 --
165array(1) {
166  [0]=>
167  string(13) "a b c d e f g"
168}
169
170-- Iteration 12 --
171array(1) {
172  [0]=>
173  string(13) "a b c d e f g"
174}
175
176-- Iteration 13 --
177array(1) {
178  [0]=>
179  string(13) "a b c d e f g"
180}
181
182-- Iteration 14 --
183array(1) {
184  [0]=>
185  string(13) "a b c d e f g"
186}
187
188-- Iteration 15 --
189array(1) {
190  [0]=>
191  string(13) "a b c d e f g"
192}
193
194-- Iteration 16 --
195array(1) {
196  [0]=>
197  string(13) "a b c d e f g"
198}
199
200-- Iteration 17 --
201array(1) {
202  [0]=>
203  string(13) "a b c d e f g"
204}
205
206-- Iteration 18 --
207array(1) {
208  [0]=>
209  string(13) "a b c d e f g"
210}
211
212-- Iteration 19 --
213array(1) {
214  [0]=>
215  string(13) "a b c d e f g"
216}
217
218-- Iteration 20 --
219array(1) {
220  [0]=>
221  string(13) "a b c d e f g"
222}
223
224-- Iteration 21 --
225array(1) {
226  [0]=>
227  string(13) "a b c d e f g"
228}
229
230-- Iteration 22 --
231array(1) {
232  [0]=>
233  string(13) "a b c d e f g"
234}
235
236-- Iteration 23 --
237array(1) {
238  [0]=>
239  string(13) "a b c d e f g"
240}
241
242-- Iteration 24 --
243
244Warning: mb_split() expects parameter 1 to be string, resource given in %s on line %d
245bool(false)
246Done
247