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