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--INI-- 9error_reporting=E_ALL & ~E_DEPRECATED 10--FILE-- 11<?php 12/* Prototype : bool iconv_set_encoding(string type, string charset) 13 * Description: Sets internal encoding and output encoding for ob_iconv_handler() 14 * Source code: ext/iconv/iconv.c 15 */ 16 17/* 18 * Test Error functionality of iconv_get_encoding 19 */ 20 21echo "*** Testing iconv_set_encoding() : error functionality ***\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 37Nothing 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 // invalid string data 74/*18*/ "Nothing", 75 'Nothing', 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_regex_encoding() 92$iterator = 1; 93foreach($inputs as $input) { 94 echo "\n-- Iteration $iterator --\n"; 95 var_dump( iconv_set_encoding("internal_encoding", $input) ); 96 var_dump( iconv_set_encoding("input_encoding", $input) ); 97 var_dump( iconv_set_encoding("output_encoding", $input) ); 98 var_dump( iconv_get_encoding("internal_encoding") ); 99 var_dump( iconv_get_encoding("input_encoding") ); 100 var_dump( iconv_get_encoding("output_encoding") ); 101 102 $iterator++; 103}; 104 105fclose($fp); 106 107echo "Done"; 108?> 109--EXPECTF-- 110*** Testing iconv_set_encoding() : error functionality *** 111 112-- Iteration 1 -- 113bool(true) 114bool(true) 115bool(true) 116string(1) "0" 117string(1) "0" 118string(1) "0" 119 120-- Iteration 2 -- 121bool(true) 122bool(true) 123bool(true) 124string(1) "1" 125string(1) "1" 126string(1) "1" 127 128-- Iteration 3 -- 129bool(true) 130bool(true) 131bool(true) 132string(5) "12345" 133string(5) "12345" 134string(5) "12345" 135 136-- Iteration 4 -- 137bool(true) 138bool(true) 139bool(true) 140string(5) "-2345" 141string(5) "-2345" 142string(5) "-2345" 143 144-- Iteration 5 -- 145bool(true) 146bool(true) 147bool(true) 148string(4) "10.5" 149string(4) "10.5" 150string(4) "10.5" 151 152-- Iteration 6 -- 153bool(true) 154bool(true) 155bool(true) 156string(5) "-10.5" 157string(5) "-10.5" 158string(5) "-10.5" 159 160-- Iteration 7 -- 161bool(true) 162bool(true) 163bool(true) 164string(12) "123456789000" 165string(12) "123456789000" 166string(12) "123456789000" 167 168-- Iteration 8 -- 169bool(true) 170bool(true) 171bool(true) 172string(13) "1.23456789E-9" 173string(13) "1.23456789E-9" 174string(13) "1.23456789E-9" 175 176-- Iteration 9 -- 177bool(true) 178bool(true) 179bool(true) 180string(3) "0.5" 181string(3) "0.5" 182string(3) "0.5" 183 184-- Iteration 10 -- 185bool(true) 186bool(true) 187bool(true) 188string(5) "UTF-8" 189string(5) "UTF-8" 190string(5) "UTF-8" 191 192-- Iteration 11 -- 193bool(true) 194bool(true) 195bool(true) 196string(5) "UTF-8" 197string(5) "UTF-8" 198string(5) "UTF-8" 199 200-- Iteration 12 -- 201bool(true) 202bool(true) 203bool(true) 204string(1) "1" 205string(1) "1" 206string(1) "1" 207 208-- Iteration 13 -- 209bool(true) 210bool(true) 211bool(true) 212string(5) "UTF-8" 213string(5) "UTF-8" 214string(5) "UTF-8" 215 216-- Iteration 14 -- 217bool(true) 218bool(true) 219bool(true) 220string(1) "1" 221string(1) "1" 222string(1) "1" 223 224-- Iteration 15 -- 225bool(true) 226bool(true) 227bool(true) 228string(5) "UTF-8" 229string(5) "UTF-8" 230string(5) "UTF-8" 231 232-- Iteration 16 -- 233bool(true) 234bool(true) 235bool(true) 236string(5) "UTF-8" 237string(5) "UTF-8" 238string(5) "UTF-8" 239 240-- Iteration 17 -- 241bool(true) 242bool(true) 243bool(true) 244string(5) "UTF-8" 245string(5) "UTF-8" 246string(5) "UTF-8" 247 248-- Iteration 18 -- 249bool(true) 250bool(true) 251bool(true) 252string(7) "Nothing" 253string(7) "Nothing" 254string(7) "Nothing" 255 256-- Iteration 19 -- 257bool(true) 258bool(true) 259bool(true) 260string(7) "Nothing" 261string(7) "Nothing" 262string(7) "Nothing" 263 264-- Iteration 20 -- 265bool(true) 266bool(true) 267bool(true) 268string(7) "Nothing" 269string(7) "Nothing" 270string(7) "Nothing" 271 272-- Iteration 21 -- 273bool(true) 274bool(true) 275bool(true) 276string(5) "UTF-8" 277string(5) "UTF-8" 278string(5) "UTF-8" 279 280-- Iteration 22 -- 281bool(true) 282bool(true) 283bool(true) 284string(5) "UTF-8" 285string(5) "UTF-8" 286string(5) "UTF-8" 287 288-- Iteration 23 -- 289bool(true) 290bool(true) 291bool(true) 292string(5) "UTF-8" 293string(5) "UTF-8" 294string(5) "UTF-8" 295 296-- Iteration 24 -- 297 298Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d 299NULL 300 301Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d 302NULL 303 304Warning: iconv_set_encoding() expects parameter 2 to be string, resource given in %s on line %d 305NULL 306string(5) "UTF-8" 307string(5) "UTF-8" 308string(5) "UTF-8" 309Done 310