1--TEST-- 2Test iconv_mime_encode() function : usage variations - Pass different data types to mode arg 3--SKIPIF-- 4<?php 5PHP_INT_SIZE == 4 or die('skip'); 6extension_loaded('iconv') or die('skip'); 7function_exists('iconv_mime_decode_headers') or die("skip iconv_mime_decode_headers() is not available in this build"); 8?> 9--FILE-- 10<?php 11/* Prototype : array iconv_mime_decode_headers(string headers [, int mode, string charset]) 12 * Description: Decodes multiple mime header fields 13 * Source code: ext/iconv/iconv.c 14 */ 15 16/* 17 * Pass different data types to $str argument to see how iconv_mime_decode_headers() behaves 18 */ 19 20echo "*** Testing iconv_mime_decode_headers() : usage variations ***\n"; 21 22// Initialise function arguments not being substituted 23$headers = <<<EOF 24Subject: =?UTF-8?B?QSBTYW1wbGUgVGVzdA==?= 25To: example@example.com 26Date: Thu, 1 Jan 1970 00:00:00 +0000 27Message-Id: <example@example.com> 28Received: from localhost (localhost [127.0.0.1]) by localhost 29 with SMTP id example for <example@example.com>; 30 Thu, 1 Jan 1970 00:00:00 +0000 (UTC) 31 (envelope-from example-return-0000-example=example.com@example.com) 32Received: (qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000 33 34EOF; 35 36$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR; 37$charset = 'UTF-8'; 38 39 40//get an unset variable 41$unset_var = 10; 42unset ($unset_var); 43 44// get a class 45class classA 46{ 47 public function __toString() { 48 return "Class A object"; 49 } 50} 51 52// heredoc string 53$heredoc = <<<EOT 54hello world 55EOT; 56 57// get a resource variable 58$fp = fopen(__FILE__, "r"); 59 60// unexpected values to be passed to $str argument 61$inputs = array( 62 63 // int data 64/*1*/ 0, 65 1, 66 12345, 67 -2345, 68 69 // float data 70/*5*/ 10.5, 71 -10.5, 72 12.3456789000e10, 73 12.3456789000E-10, 74 .5, 75 76 // null data 77/*10*/ NULL, 78 null, 79 80 // boolean data 81/*12*/ true, 82 false, 83 TRUE, 84 FALSE, 85 86 // empty data 87/*16*/ "", 88 '', 89 90 // string data 91/*18*/ "string", 92 'string', 93 $heredoc, 94 95 // object data 96/*21*/ new classA(), 97 98 // undefined data 99/*22*/ @$undefined_var, 100 101 // unset data 102/*23*/ @$unset_var, 103 104 // resource variable 105/*24*/ $fp 106); 107 108// loop through each element of $inputs to check the behavior of iconv_mime_decode_headers() 109$iterator = 1; 110foreach($inputs as $input) { 111 echo "\n-- Iteration $iterator --\n"; 112 var_dump( iconv_mime_decode_headers($headers, $input, $charset)); 113 $iterator++; 114}; 115 116fclose($fp); 117 118echo "Done"; 119?> 120--EXPECTF-- 121*** Testing iconv_mime_decode_headers() : usage variations *** 122 123-- Iteration 1 -- 124array(5) { 125 ["Subject"]=> 126 string(13) "A Sample Test" 127 ["To"]=> 128 string(19) "example@example.com" 129 ["Date"]=> 130 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 131 ["Message-Id"]=> 132 string(21) "<example@example.com>" 133 ["Received"]=> 134 array(2) { 135 [0]=> 136 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 137 [1]=> 138 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 139 } 140} 141 142-- Iteration 2 -- 143array(5) { 144 ["Subject"]=> 145 string(13) "A Sample Test" 146 ["To"]=> 147 string(19) "example@example.com" 148 ["Date"]=> 149 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 150 ["Message-Id"]=> 151 string(21) "<example@example.com>" 152 ["Received"]=> 153 array(2) { 154 [0]=> 155 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 156 [1]=> 157 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 158 } 159} 160 161-- Iteration 3 -- 162array(5) { 163 ["Subject"]=> 164 string(13) "A Sample Test" 165 ["To"]=> 166 string(19) "example@example.com" 167 ["Date"]=> 168 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 169 ["Message-Id"]=> 170 string(21) "<example@example.com>" 171 ["Received"]=> 172 array(2) { 173 [0]=> 174 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 175 [1]=> 176 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 177 } 178} 179 180-- Iteration 4 -- 181array(5) { 182 ["Subject"]=> 183 string(13) "A Sample Test" 184 ["To"]=> 185 string(19) "example@example.com" 186 ["Date"]=> 187 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 188 ["Message-Id"]=> 189 string(21) "<example@example.com>" 190 ["Received"]=> 191 array(2) { 192 [0]=> 193 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 194 [1]=> 195 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 196 } 197} 198 199-- Iteration 5 -- 200array(5) { 201 ["Subject"]=> 202 string(13) "A Sample Test" 203 ["To"]=> 204 string(19) "example@example.com" 205 ["Date"]=> 206 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 207 ["Message-Id"]=> 208 string(21) "<example@example.com>" 209 ["Received"]=> 210 array(2) { 211 [0]=> 212 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 213 [1]=> 214 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 215 } 216} 217 218-- Iteration 6 -- 219array(5) { 220 ["Subject"]=> 221 string(13) "A Sample Test" 222 ["To"]=> 223 string(19) "example@example.com" 224 ["Date"]=> 225 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 226 ["Message-Id"]=> 227 string(21) "<example@example.com>" 228 ["Received"]=> 229 array(2) { 230 [0]=> 231 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 232 [1]=> 233 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 234 } 235} 236 237-- Iteration 7 -- 238 239Warning: iconv_mime_decode_headers() expects parameter 2 to be integer, float given in %s on line %d 240bool(false) 241 242-- Iteration 8 -- 243array(5) { 244 ["Subject"]=> 245 string(13) "A Sample Test" 246 ["To"]=> 247 string(19) "example@example.com" 248 ["Date"]=> 249 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 250 ["Message-Id"]=> 251 string(21) "<example@example.com>" 252 ["Received"]=> 253 array(2) { 254 [0]=> 255 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 256 [1]=> 257 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 258 } 259} 260 261-- Iteration 9 -- 262array(5) { 263 ["Subject"]=> 264 string(13) "A Sample Test" 265 ["To"]=> 266 string(19) "example@example.com" 267 ["Date"]=> 268 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 269 ["Message-Id"]=> 270 string(21) "<example@example.com>" 271 ["Received"]=> 272 array(2) { 273 [0]=> 274 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 275 [1]=> 276 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 277 } 278} 279 280-- Iteration 10 -- 281array(5) { 282 ["Subject"]=> 283 string(13) "A Sample Test" 284 ["To"]=> 285 string(19) "example@example.com" 286 ["Date"]=> 287 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 288 ["Message-Id"]=> 289 string(21) "<example@example.com>" 290 ["Received"]=> 291 array(2) { 292 [0]=> 293 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 294 [1]=> 295 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 296 } 297} 298 299-- Iteration 11 -- 300array(5) { 301 ["Subject"]=> 302 string(13) "A Sample Test" 303 ["To"]=> 304 string(19) "example@example.com" 305 ["Date"]=> 306 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 307 ["Message-Id"]=> 308 string(21) "<example@example.com>" 309 ["Received"]=> 310 array(2) { 311 [0]=> 312 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 313 [1]=> 314 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 315 } 316} 317 318-- Iteration 12 -- 319array(5) { 320 ["Subject"]=> 321 string(13) "A Sample Test" 322 ["To"]=> 323 string(19) "example@example.com" 324 ["Date"]=> 325 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 326 ["Message-Id"]=> 327 string(21) "<example@example.com>" 328 ["Received"]=> 329 array(2) { 330 [0]=> 331 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 332 [1]=> 333 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 334 } 335} 336 337-- Iteration 13 -- 338array(5) { 339 ["Subject"]=> 340 string(13) "A Sample Test" 341 ["To"]=> 342 string(19) "example@example.com" 343 ["Date"]=> 344 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 345 ["Message-Id"]=> 346 string(21) "<example@example.com>" 347 ["Received"]=> 348 array(2) { 349 [0]=> 350 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 351 [1]=> 352 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 353 } 354} 355 356-- Iteration 14 -- 357array(5) { 358 ["Subject"]=> 359 string(13) "A Sample Test" 360 ["To"]=> 361 string(19) "example@example.com" 362 ["Date"]=> 363 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 364 ["Message-Id"]=> 365 string(21) "<example@example.com>" 366 ["Received"]=> 367 array(2) { 368 [0]=> 369 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 370 [1]=> 371 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 372 } 373} 374 375-- Iteration 15 -- 376array(5) { 377 ["Subject"]=> 378 string(13) "A Sample Test" 379 ["To"]=> 380 string(19) "example@example.com" 381 ["Date"]=> 382 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 383 ["Message-Id"]=> 384 string(21) "<example@example.com>" 385 ["Received"]=> 386 array(2) { 387 [0]=> 388 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 389 [1]=> 390 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 391 } 392} 393 394-- Iteration 16 -- 395 396Warning: iconv_mime_decode_headers() expects parameter 2 to be integer, string given in %s on line %d 397bool(false) 398 399-- Iteration 17 -- 400 401Warning: iconv_mime_decode_headers() expects parameter 2 to be integer, string given in %s on line %d 402bool(false) 403 404-- Iteration 18 -- 405 406Warning: iconv_mime_decode_headers() expects parameter 2 to be integer, string given in %s on line %d 407bool(false) 408 409-- Iteration 19 -- 410 411Warning: iconv_mime_decode_headers() expects parameter 2 to be integer, string given in %s on line %d 412bool(false) 413 414-- Iteration 20 -- 415 416Warning: iconv_mime_decode_headers() expects parameter 2 to be integer, string given in %s on line %d 417bool(false) 418 419-- Iteration 21 -- 420 421Warning: iconv_mime_decode_headers() expects parameter 2 to be integer, object given in %s on line %d 422bool(false) 423 424-- Iteration 22 -- 425array(5) { 426 ["Subject"]=> 427 string(13) "A Sample Test" 428 ["To"]=> 429 string(19) "example@example.com" 430 ["Date"]=> 431 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 432 ["Message-Id"]=> 433 string(21) "<example@example.com>" 434 ["Received"]=> 435 array(2) { 436 [0]=> 437 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 438 [1]=> 439 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 440 } 441} 442 443-- Iteration 23 -- 444array(5) { 445 ["Subject"]=> 446 string(13) "A Sample Test" 447 ["To"]=> 448 string(19) "example@example.com" 449 ["Date"]=> 450 string(30) "Thu, 1 Jan 1970 00:00:00 +0000" 451 ["Message-Id"]=> 452 string(21) "<example@example.com>" 453 ["Received"]=> 454 array(2) { 455 [0]=> 456 string(204) "from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)" 457 [1]=> 458 string(57) "(qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000" 459 } 460} 461 462-- Iteration 24 -- 463 464Warning: iconv_mime_decode_headers() expects parameter 2 to be integer, resource given in %s on line %d 465bool(false) 466Done 467