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