1--TEST-- 2Test mb_internal_encoding() function : usage variations - Pass different data types as $encoding arg 3--SKIPIF-- 4<?php 5extension_loaded('mbstring') or die('skip'); 6function_exists('mb_internal_encoding') or die("skip mb_internal_encoding() is not available in this build"); 7?> 8--FILE-- 9<?php 10/* Prototype : string mb_internal_encoding([string $encoding]) 11 * Description: Sets the current internal encoding or Returns 12 * the current internal encoding as a string 13 * Source code: ext/mbstring/mbstring.c 14 */ 15 16/* 17 * Pass different data types as $encoding to mb_internal_encoding() to test behaviour 18 * Where possible 'UTF-8' has been entered as a string value 19 */ 20 21echo "*** Testing mb_internal_encoding() : usage variations ***\n"; 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 $inputs to check the behavior of mb_internal_encoding() 92$iterator = 1; 93foreach($inputs as $input) { 94 echo "\n-- Iteration $iterator --\n"; 95 var_dump( mb_internal_encoding($input) ); 96 $iterator++; 97}; 98 99fclose($fp); 100echo "Done"; 101?> 102--EXPECTF-- 103*** Testing mb_internal_encoding() : usage variations *** 104 105-- Iteration 1 -- 106 107Warning: mb_internal_encoding(): Unknown encoding "0" in %s on line %d 108bool(false) 109 110-- Iteration 2 -- 111 112Warning: mb_internal_encoding(): Unknown encoding "1" in %s on line %d 113bool(false) 114 115-- Iteration 3 -- 116 117Warning: mb_internal_encoding(): Unknown encoding "12345" in %s on line %d 118bool(false) 119 120-- Iteration 4 -- 121 122Warning: mb_internal_encoding(): Unknown encoding "-2345" in %s on line %d 123bool(false) 124 125-- Iteration 5 -- 126 127Warning: mb_internal_encoding(): Unknown encoding "10.5" in %s on line %d 128bool(false) 129 130-- Iteration 6 -- 131 132Warning: mb_internal_encoding(): Unknown encoding "-10.5" in %s on line %d 133bool(false) 134 135-- Iteration 7 -- 136 137Warning: mb_internal_encoding(): Unknown encoding "123456789000" in %s on line %d 138bool(false) 139 140-- Iteration 8 -- 141 142Warning: mb_internal_encoding(): Unknown encoding "1.23456789E-9" in %s on line %d 143bool(false) 144 145-- Iteration 9 -- 146 147Warning: mb_internal_encoding(): Unknown encoding "0.5" in %s on line %d 148bool(false) 149 150-- Iteration 10 -- 151 152Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d 153bool(false) 154 155-- Iteration 11 -- 156 157Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d 158bool(false) 159 160-- Iteration 12 -- 161 162Warning: mb_internal_encoding(): Unknown encoding "1" in %s on line %d 163bool(false) 164 165-- Iteration 13 -- 166 167Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d 168bool(false) 169 170-- Iteration 14 -- 171 172Warning: mb_internal_encoding(): Unknown encoding "1" in %s on line %d 173bool(false) 174 175-- Iteration 15 -- 176 177Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d 178bool(false) 179 180-- Iteration 16 -- 181 182Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d 183bool(false) 184 185-- Iteration 17 -- 186 187Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d 188bool(false) 189 190-- Iteration 18 -- 191bool(true) 192 193-- Iteration 19 -- 194bool(true) 195 196-- Iteration 20 -- 197bool(true) 198 199-- Iteration 21 -- 200bool(true) 201 202-- Iteration 22 -- 203 204Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d 205bool(false) 206 207-- Iteration 23 -- 208 209Warning: mb_internal_encoding(): Unknown encoding "" in %s on line %d 210bool(false) 211 212-- Iteration 24 -- 213 214Warning: mb_internal_encoding() expects parameter 1 to be string, resource given in %s on line %d 215NULL 216Done 217