1--TEST--
2Test mb_encode_mimeheader() function : usage variations - Pass different data types to $str 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 $str argument to see how mb_encode_mimeheader() behaves
18 */
19
20echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
21
22// Initialise function arguments not being substituted
23$charset = 'utf-8';
24$transfer_encoding = 'B';
25$linefeed = "\r\n";
26$indent = 2;
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 mb_encode_mimeheader()
97$iterator = 1;
98foreach($inputs as $input) {
99  echo "\n-- Iteration $iterator --\n";
100  var_dump( mb_encode_mimeheader($input, $charset, $transfer_encoding, $linefeed, $indent));
101  $iterator++;
102};
103
104fclose($fp);
105
106echo "Done";
107?>
108--EXPECTF--
109*** Testing mb_encode_mimeheader() : usage variations ***
110
111-- Iteration 1 --
112string(1) "0"
113
114-- Iteration 2 --
115string(1) "1"
116
117-- Iteration 3 --
118string(5) "12345"
119
120-- Iteration 4 --
121string(5) "-2345"
122
123-- Iteration 5 --
124string(4) "10.5"
125
126-- Iteration 6 --
127string(5) "-10.5"
128
129-- Iteration 7 --
130string(12) "123456789000"
131
132-- Iteration 8 --
133string(13) "1.23456789E-9"
134
135-- Iteration 9 --
136string(3) "0.5"
137
138-- Iteration 10 --
139string(0) ""
140
141-- Iteration 11 --
142string(0) ""
143
144-- Iteration 12 --
145string(1) "1"
146
147-- Iteration 13 --
148string(0) ""
149
150-- Iteration 14 --
151string(1) "1"
152
153-- Iteration 15 --
154string(0) ""
155
156-- Iteration 16 --
157string(0) ""
158
159-- Iteration 17 --
160string(0) ""
161
162-- Iteration 18 --
163string(6) "string"
164
165-- Iteration 19 --
166string(6) "string"
167
168-- Iteration 20 --
169string(11) "hello world"
170
171-- Iteration 21 --
172string(14) "Class A object"
173
174-- Iteration 22 --
175string(0) ""
176
177-- Iteration 23 --
178string(0) ""
179
180-- Iteration 24 --
181
182Warning: mb_encode_mimeheader() expects parameter 1 to be string, resource given in %s on line %d
183NULL
184Done