1--TEST--
2Test iconv_mime_decode() 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') or die("skip iconv_mime_decode() is not available in this build");
8?>
9--FILE--
10<?php
11/* Prototype  : string iconv_mime_decode(string encoded_string [, int mode, string charset])
12 * Description: Decodes a mime header field
13 * Source code: ext/iconv/iconv.c
14 */
15
16/*
17 * Pass different data types to $str argument to see how iconv_mime_decode() behaves
18 */
19
20echo "*** Testing iconv_mime_decode() : usage variations ***\n";
21
22// Initialise function arguments not being substituted
23$header = b'Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=';
24$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR;
25$charset = 'UTF-8';
26
27
28//get an unset variable
29$unset_var = 10;
30unset ($unset_var);
31
32// get a class
33class classA
34{
35  public function __toString() {
36    return "Class A object";
37  }
38}
39
40// heredoc string
41$heredoc = <<<EOT
42hello world
43EOT;
44
45// get a resource variable
46$fp = fopen(__FILE__, "r");
47
48// unexpected values to be passed to $str argument
49$inputs = array(
50
51       // int data
52/*1*/  0,
53       1,
54       12345,
55       -2345,
56
57       // float data
58/*5*/  10.5,
59       -10.5,
60       12.3456789000e10,
61       12.3456789000E-10,
62       .5,
63
64       // null data
65/*10*/ NULL,
66       null,
67
68       // boolean data
69/*12*/ true,
70       false,
71       TRUE,
72       FALSE,
73
74       // empty data
75/*16*/ "",
76       '',
77
78       // string data
79/*18*/ "string",
80       'string',
81       $heredoc,
82
83       // object data
84/*21*/ new classA(),
85
86       // undefined data
87/*22*/ @$undefined_var,
88
89       // unset data
90/*23*/ @$unset_var,
91
92       // resource variable
93/*24*/ $fp
94);
95
96// loop through each element of $inputs to check the behavior of iconv_mime_decode()
97$iterator = 1;
98foreach($inputs as $input) {
99  echo "\n-- Iteration $iterator --\n";
100  var_dump( bin2hex(iconv_mime_decode($header, $input, $charset)));
101  $iterator++;
102};
103
104fclose($fp);
105
106echo "Done";
107?>
108--EXPECTF--
109*** Testing iconv_mime_decode() : usage variations ***
110
111-- Iteration 1 --
112string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
113
114-- Iteration 2 --
115string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
116
117-- Iteration 3 --
118string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
119
120-- Iteration 4 --
121string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
122
123-- Iteration 5 --
124string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
125
126-- Iteration 6 --
127string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
128
129-- Iteration 7 --
130
131Warning: iconv_mime_decode() expects parameter 2 to be integer, float given in %s on line %d
132string(0) ""
133
134-- Iteration 8 --
135string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
136
137-- Iteration 9 --
138string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
139
140-- Iteration 10 --
141string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
142
143-- Iteration 11 --
144string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
145
146-- Iteration 12 --
147string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
148
149-- Iteration 13 --
150string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
151
152-- Iteration 14 --
153string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
154
155-- Iteration 15 --
156string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
157
158-- Iteration 16 --
159
160Warning: iconv_mime_decode() expects parameter 2 to be integer, string given in %s on line %d
161string(0) ""
162
163-- Iteration 17 --
164
165Warning: iconv_mime_decode() expects parameter 2 to be integer, string given in %s on line %d
166string(0) ""
167
168-- Iteration 18 --
169
170Warning: iconv_mime_decode() expects parameter 2 to be integer, string given in %s on line %d
171string(0) ""
172
173-- Iteration 19 --
174
175Warning: iconv_mime_decode() expects parameter 2 to be integer, string given in %s on line %d
176string(0) ""
177
178-- Iteration 20 --
179
180Warning: iconv_mime_decode() expects parameter 2 to be integer, string given in %s on line %d
181string(0) ""
182
183-- Iteration 21 --
184
185Warning: iconv_mime_decode() expects parameter 2 to be integer, object given in %s on line %d
186string(0) ""
187
188-- Iteration 22 --
189string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
190
191-- Iteration 23 --
192string(52) "5375626a6563743a205072c3bc66756e67205072c3bc66756e67"
193
194-- Iteration 24 --
195
196Warning: iconv_mime_decode() expects parameter 2 to be integer, resource given in %s on line %d
197string(0) ""
198Done
199