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 -- 159 160Warning: mb_split(): Empty regular expression in %s on line %d 161array(1) { 162 [0]=> 163 string(13) "a b c d e f g" 164} 165 166-- Iteration 11 -- 167 168Warning: mb_split(): Empty regular expression in %s on line %d 169array(1) { 170 [0]=> 171 string(13) "a b c d e f g" 172} 173 174-- Iteration 12 -- 175array(1) { 176 [0]=> 177 string(13) "a b c d e f g" 178} 179 180-- Iteration 13 -- 181 182Warning: mb_split(): Empty regular expression in %s on line %d 183array(1) { 184 [0]=> 185 string(13) "a b c d e f g" 186} 187 188-- Iteration 14 -- 189array(1) { 190 [0]=> 191 string(13) "a b c d e f g" 192} 193 194-- Iteration 15 -- 195 196Warning: mb_split(): Empty regular expression in %s on line %d 197array(1) { 198 [0]=> 199 string(13) "a b c d e f g" 200} 201 202-- Iteration 16 -- 203 204Warning: mb_split(): Empty regular expression in %s on line %d 205array(1) { 206 [0]=> 207 string(13) "a b c d e f g" 208} 209 210-- Iteration 17 -- 211 212Warning: mb_split(): Empty regular expression in %s on line %d 213array(1) { 214 [0]=> 215 string(13) "a b c d e f g" 216} 217 218-- Iteration 18 -- 219array(1) { 220 [0]=> 221 string(13) "a b c d e f g" 222} 223 224-- Iteration 19 -- 225array(1) { 226 [0]=> 227 string(13) "a b c d e f g" 228} 229 230-- Iteration 20 -- 231array(1) { 232 [0]=> 233 string(13) "a b c d e f g" 234} 235 236-- Iteration 21 -- 237array(1) { 238 [0]=> 239 string(13) "a b c d e f g" 240} 241 242-- Iteration 22 -- 243 244Warning: mb_split(): Empty regular expression in %s on line %d 245array(1) { 246 [0]=> 247 string(13) "a b c d e f g" 248} 249 250-- Iteration 23 -- 251 252Warning: mb_split(): Empty regular expression in %s on line %d 253array(1) { 254 [0]=> 255 string(13) "a b c d e f g" 256} 257 258-- Iteration 24 -- 259 260Warning: mb_split() expects parameter 1 to be string, resource given in %s on line %d 261bool(false) 262Done