1--TEST-- 2Test iconv_set_encoding() function : error functionality 3--SKIPIF-- 4<?php 5extension_loaded('iconv') or die('skip'); 6function_exists('iconv_set_encoding') or die("skip iconv_set_encoding() is not available in this build"); 7?> 8--FILE-- 9<?php 10/* Prototype : bool iconv_set_encoding(string type, string charset) 11 * Description: Sets internal encoding and output encoding for ob_iconv_handler() 12 * Source code: ext/iconv/iconv.c 13 */ 14 15/* 16 * Test Error functionality of iconv_get_encoding 17 */ 18 19echo "*** Testing iconv_set_encoding() : error functionality ***\n"; 20 21//get an unset variable 22$unset_var = 10; 23unset ($unset_var); 24 25// get a class 26class classA 27{ 28 public function __toString() { 29 return "UTF-8"; 30 } 31} 32 33// heredoc string 34$heredoc = <<<EOT 35Nothing 36EOT; 37 38// get a resource variable 39$fp = fopen(__FILE__, "r"); 40 41// unexpected values to be passed to $encoding argument 42$inputs = array( 43 44 // int data 45/*1*/ 0, 46 1, 47 12345, 48 -2345, 49 50 // float data 51/*5*/ 10.5, 52 -10.5, 53 12.3456789000e10, 54 12.3456789000E-10, 55 .5, 56 57 // null data 58/*10*/ NULL, 59 null, 60 61 // boolean data 62/*12*/ true, 63 false, 64 TRUE, 65 FALSE, 66 67 // empty data 68/*16*/ "", 69 '', 70 71 // invalid string data 72/*18*/ "Nothing", 73 'Nothing', 74 $heredoc, 75 76 // object data 77/*21*/ new classA(), 78 79 // undefined data 80/*22*/ @$undefined_var, 81 82 // unset data 83/*23*/ @$unset_var, 84 85 // resource variable 86/*24*/ $fp 87); 88 89// loop through each element of $inputs to check the behavior of mb_regex_encoding() 90$iterator = 1; 91foreach($inputs as $input) { 92 echo "\n-- Iteration $iterator --\n"; 93 var_dump( iconv_set_encoding("internal_encoding", $input) ); 94 var_dump( iconv_set_encoding("input_encoding", $input) ); 95 var_dump( iconv_set_encoding("output_encoding", $input) ); 96 var_dump( iconv_get_encoding("internal_encoding") ); 97 var_dump( iconv_get_encoding("input_encoding") ); 98 var_dump( iconv_get_encoding("output_encoding") ); 99 100 $iterator++; 101}; 102 103fclose($fp); 104 105echo "Done"; 106?> 107--EXPECTF-- 108*** Testing iconv_set_encoding() : error functionality *** 109 110-- Iteration 1 -- 111bool(true) 112bool(true) 113bool(true) 114string(1) "0" 115string(1) "0" 116string(1) "0" 117 118-- Iteration 2 -- 119bool(true) 120bool(true) 121bool(true) 122string(1) "1" 123string(1) "1" 124string(1) "1" 125 126-- Iteration 3 -- 127bool(true) 128bool(true) 129bool(true) 130string(5) "12345" 131string(5) "12345" 132string(5) "12345" 133 134-- Iteration 4 -- 135bool(true) 136bool(true) 137bool(true) 138string(5) "-2345" 139string(5) "-2345" 140string(5) "-2345" 141 142-- Iteration 5 -- 143bool(true) 144bool(true) 145bool(true) 146string(4) "10.5" 147string(4) "10.5" 148string(4) "10.5" 149 150-- Iteration 6 -- 151bool(true) 152bool(true) 153bool(true) 154string(5) "-10.5" 155string(5) "-10.5" 156string(5) "-10.5" 157 158-- Iteration 7 -- 159bool(true) 160bool(true) 161bool(true) 162string(12) "123456789000" 163string(12) "123456789000" 164string(12) "123456789000" 165 166-- Iteration 8 -- 167bool(true) 168bool(true) 169bool(true) 170string(13) "1.23456789E-9" 171string(13) "1.23456789E-9" 172string(13) "1.23456789E-9" 173 174-- Iteration 9 -- 175bool(true) 176bool(true) 177bool(true) 178string(3) "0.5" 179string(3) "0.5" 180string(3) "0.5" 181 182-- Iteration 10 -- 183bool(true) 184bool(true) 185bool(true) 186string(0) "" 187string(0) "" 188string(0) "" 189 190-- Iteration 11 -- 191bool(true) 192bool(true) 193bool(true) 194string(0) "" 195string(0) "" 196string(0) "" 197 198-- Iteration 12 -- 199bool(true) 200bool(true) 201bool(true) 202string(1) "1" 203string(1) "1" 204string(1) "1" 205 206-- Iteration 13 -- 207bool(true) 208bool(true) 209bool(true) 210string(0) "" 211string(0) "" 212string(0) "" 213 214-- Iteration 14 -- 215bool(true) 216bool(true) 217bool(true) 218string(1) "1" 219string(1) "1" 220string(1) "1" 221 222-- Iteration 15 -- 223bool(true) 224bool(true) 225bool(true) 226string(0) "" 227string(0) "" 228string(0) "" 229 230-- Iteration 16 -- 231bool(true) 232bool(true) 233bool(true) 234string(0) "" 235string(0) "" 236string(0) "" 237 238-- Iteration 17 -- 239bool(true) 240bool(true) 241bool(true) 242string(0) "" 243string(0) "" 244string(0) "" 245 246-- Iteration 18 -- 247bool(true) 248bool(true) 249bool(true) 250string(7) "Nothing" 251string(7) "Nothing" 252string(7) "Nothing" 253 254-- Iteration 19 -- 255bool(true) 256bool(true) 257bool(true) 258string(7) "Nothing" 259string(7) "Nothing" 260string(7) "Nothing" 261 262-- Iteration 20 -- 263bool(true) 264bool(true) 265bool(true) 266string(7) "Nothing" 267string(7) "Nothing" 268string(7) "Nothing" 269 270-- Iteration 21 -- 271bool(true) 272bool(true) 273bool(true) 274string(5) "UTF-8" 275string(5) "UTF-8" 276string(5) "UTF-8" 277 278-- Iteration 22 -- 279bool(true) 280bool(true) 281bool(true) 282string(0) "" 283string(0) "" 284string(0) "" 285 286-- Iteration 23 -- 287bool(true) 288bool(true) 289bool(true) 290string(0) "" 291string(0) "" 292string(0) "" 293 294-- Iteration 24 -- 295 296Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d 297NULL 298 299Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d 300NULL 301 302Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d 303NULL 304string(0) "" 305string(0) "" 306string(0) "" 307Done