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