1--TEST--
2Test iconv_mime_encode() function : usage variations - Pass different data types to headers 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?UHLDvGZ1bmcgUHLDvGZ1bmc=?=
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 = 'ISO-8859-1';
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($input, $mode, $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(0) {
124}
125
126-- Iteration 2 --
127array(0) {
128}
129
130-- Iteration 3 --
131array(0) {
132}
133
134-- Iteration 4 --
135array(0) {
136}
137
138-- Iteration 5 --
139array(0) {
140}
141
142-- Iteration 6 --
143array(0) {
144}
145
146-- Iteration 7 --
147array(0) {
148}
149
150-- Iteration 8 --
151array(0) {
152}
153
154-- Iteration 9 --
155array(0) {
156}
157
158-- Iteration 10 --
159array(0) {
160}
161
162-- Iteration 11 --
163array(0) {
164}
165
166-- Iteration 12 --
167array(0) {
168}
169
170-- Iteration 13 --
171array(0) {
172}
173
174-- Iteration 14 --
175array(0) {
176}
177
178-- Iteration 15 --
179array(0) {
180}
181
182-- Iteration 16 --
183array(0) {
184}
185
186-- Iteration 17 --
187array(0) {
188}
189
190-- Iteration 18 --
191array(0) {
192}
193
194-- Iteration 19 --
195array(0) {
196}
197
198-- Iteration 20 --
199array(0) {
200}
201
202-- Iteration 21 --
203array(0) {
204}
205
206-- Iteration 22 --
207array(0) {
208}
209
210-- Iteration 23 --
211array(0) {
212}
213
214-- Iteration 24 --
215
216Warning: iconv_mime_decode_headers() expects parameter 1 to be string, resource given in %s on line %d
217bool(false)
218Done