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