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