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"); 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$pattern = '[a-z]'; 20$string = 'string_val'; 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($pattern, $string, $input) ); 96 $iterator++; 97}; 98 99fclose($fp); 100echo "Done"; 101?> 102--EXPECTF-- 103*** Testing mb_split() : usage variations *** 104 105-- Iteration 1 -- 106array(1) { 107 [0]=> 108 string(10) "string_val" 109} 110 111-- Iteration 2 -- 112array(1) { 113 [0]=> 114 string(10) "string_val" 115} 116 117-- Iteration 3 -- 118array(10) { 119 [0]=> 120 string(0) "" 121 [1]=> 122 string(0) "" 123 [2]=> 124 string(0) "" 125 [3]=> 126 string(0) "" 127 [4]=> 128 string(0) "" 129 [5]=> 130 string(0) "" 131 [6]=> 132 string(1) "_" 133 [7]=> 134 string(0) "" 135 [8]=> 136 string(0) "" 137 [9]=> 138 string(0) "" 139} 140 141-- Iteration 4 -- 142array(10) { 143 [0]=> 144 string(0) "" 145 [1]=> 146 string(0) "" 147 [2]=> 148 string(0) "" 149 [3]=> 150 string(0) "" 151 [4]=> 152 string(0) "" 153 [5]=> 154 string(0) "" 155 [6]=> 156 string(1) "_" 157 [7]=> 158 string(0) "" 159 [8]=> 160 string(0) "" 161 [9]=> 162 string(0) "" 163} 164 165-- Iteration 5 -- 166array(10) { 167 [0]=> 168 string(0) "" 169 [1]=> 170 string(0) "" 171 [2]=> 172 string(0) "" 173 [3]=> 174 string(0) "" 175 [4]=> 176 string(0) "" 177 [5]=> 178 string(0) "" 179 [6]=> 180 string(1) "_" 181 [7]=> 182 string(0) "" 183 [8]=> 184 string(0) "" 185 [9]=> 186 string(0) "" 187} 188 189-- Iteration 6 -- 190array(10) { 191 [0]=> 192 string(0) "" 193 [1]=> 194 string(0) "" 195 [2]=> 196 string(0) "" 197 [3]=> 198 string(0) "" 199 [4]=> 200 string(0) "" 201 [5]=> 202 string(0) "" 203 [6]=> 204 string(1) "_" 205 [7]=> 206 string(0) "" 207 [8]=> 208 string(0) "" 209 [9]=> 210 string(0) "" 211} 212 213-- Iteration 7 -- 214array(10) { 215 [0]=> 216 string(0) "" 217 [1]=> 218 string(0) "" 219 [2]=> 220 string(0) "" 221 [3]=> 222 string(0) "" 223 [4]=> 224 string(0) "" 225 [5]=> 226 string(0) "" 227 [6]=> 228 string(1) "_" 229 [7]=> 230 string(0) "" 231 [8]=> 232 string(0) "" 233 [9]=> 234 string(0) "" 235} 236 237-- Iteration 8 -- 238array(1) { 239 [0]=> 240 string(10) "string_val" 241} 242 243-- Iteration 9 -- 244array(1) { 245 [0]=> 246 string(10) "string_val" 247} 248 249-- Iteration 10 -- 250array(1) { 251 [0]=> 252 string(10) "string_val" 253} 254 255-- Iteration 11 -- 256array(1) { 257 [0]=> 258 string(10) "string_val" 259} 260 261-- Iteration 12 -- 262array(1) { 263 [0]=> 264 string(10) "string_val" 265} 266 267-- Iteration 13 -- 268array(1) { 269 [0]=> 270 string(10) "string_val" 271} 272 273-- Iteration 14 -- 274array(1) { 275 [0]=> 276 string(10) "string_val" 277} 278 279-- Iteration 15 -- 280array(1) { 281 [0]=> 282 string(10) "string_val" 283} 284 285-- Iteration 16 -- 286 287Warning: mb_split() expects parameter 3 to be long, string given in %s on line %d 288bool(false) 289 290-- Iteration 17 -- 291 292Warning: mb_split() expects parameter 3 to be long, string given in %s on line %d 293bool(false) 294 295-- Iteration 18 -- 296 297Warning: mb_split() expects parameter 3 to be long, string given in %s on line %d 298bool(false) 299 300-- Iteration 19 -- 301 302Warning: mb_split() expects parameter 3 to be long, string given in %s on line %d 303bool(false) 304 305-- Iteration 20 -- 306 307Warning: mb_split() expects parameter 3 to be long, string given in %s on line %d 308bool(false) 309 310-- Iteration 21 -- 311 312Warning: mb_split() expects parameter 3 to be long, object given in %s on line %d 313bool(false) 314 315-- Iteration 22 -- 316array(1) { 317 [0]=> 318 string(10) "string_val" 319} 320 321-- Iteration 23 -- 322array(1) { 323 [0]=> 324 string(10) "string_val" 325} 326 327-- Iteration 24 -- 328 329Warning: mb_split() expects parameter 3 to be long, resource given in %s on line %d 330bool(false) 331Done