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