1--TEST--
2Test mb_decode_mimeheader() function : usage variation
3--CREDITS--
4D. Kesley
5--SKIPIF--
6<?php
7extension_loaded('mbstring') or die('skip');
8function_exists('mb_decode_mimeheader') or die("skip mb_decode_mimeheader() is not available in this build");
9?>
10--FILE--
11<?php
12/* Prototype  : string mb_decode_mimeheader(string string)
13 * Description: Decodes the MIME "encoded-word" in the string
14 * Source code: ext/mbstring/mbstring.c
15 * Alias to functions:
16 */
17
18echo "*** Testing mb_decode_mimeheader() : usage variation ***\n";
19
20// Define error handler
21function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
22	if (error_reporting() != 0) {
23		// report non-silenced errors
24		echo "Error: $err_no - $err_msg, $filename($linenum)\n";
25	}
26}
27set_error_handler('test_error_handler');
28
29// Initialise function arguments not being substituted (if any)
30
31//get an unset variable
32$unset_var = 10;
33unset ($unset_var);
34
35// define some classes
36class classWithToString
37{
38	public function __toString() {
39		return "Class A object";
40	}
41}
42
43class classWithoutToString
44{
45}
46
47// heredoc string
48$heredoc = <<<EOT
49hello world
50EOT;
51
52// get a resource variable
53$fp = fopen(__FILE__, "r");
54
55// add arrays
56$index_array = array (1, 2, 3);
57$assoc_array = array ('one' => 1, 'two' => 2);
58
59//array of values to iterate over
60$inputs = array(
61
62      // int data
63      'int 0' => 0,
64      'int 1' => 1,
65      'int 12345' => 12345,
66      'int -12345' => -2345,
67
68      // float data
69      'float 10.5' => 10.5,
70      'float -10.5' => -10.5,
71      'float 12.3456789000e10' => 12.3456789000e10,
72      'float -12.3456789000e10' => -12.3456789000e10,
73      'float .5' => .5,
74
75      // array data
76      'empty array' => array(),
77      'int indexed array' => $index_array,
78      'associative array' => $assoc_array,
79      'nested arrays' => array('foo', $index_array, $assoc_array),
80
81      // null data
82      'uppercase NULL' => NULL,
83      'lowercase null' => null,
84
85      // boolean data
86      'lowercase true' => true,
87      'lowercase false' =>false,
88      'uppercase TRUE' =>TRUE,
89      'uppercase FALSE' =>FALSE,
90
91      // empty data
92      'empty string DQ' => "",
93      'empty string SQ' => '',
94
95      // object data
96      'instance of classWithToString' => new classWithToString(),
97      'instance of classWithoutToString' => new classWithoutToString(),
98
99      // undefined data
100      'undefined var' => @$undefined_var,
101
102      // unset data
103      'unset var' => @$unset_var,
104
105      // resource variable
106      'resource' => $fp
107);
108
109// loop through each element of the array for string
110
111foreach($inputs as $key =>$value) {
112      echo "\n--$key--\n";
113      var_dump( mb_decode_mimeheader($value) );
114};
115
116fclose($fp);
117
118?>
119===DONE===
120--EXPECTF--
121*** Testing mb_decode_mimeheader() : usage variation ***
122
123--int 0--
124string(1) "0"
125
126--int 1--
127string(1) "1"
128
129--int 12345--
130string(5) "12345"
131
132--int -12345--
133string(5) "-2345"
134
135--float 10.5--
136string(4) "10.5"
137
138--float -10.5--
139string(5) "-10.5"
140
141--float 12.3456789000e10--
142string(12) "123456789000"
143
144--float -12.3456789000e10--
145string(13) "-123456789000"
146
147--float .5--
148string(3) "0.5"
149
150--empty array--
151Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, array given, %s(%d)
152NULL
153
154--int indexed array--
155Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, array given, %s(%d)
156NULL
157
158--associative array--
159Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, array given, %s(%d)
160NULL
161
162--nested arrays--
163Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, array given, %s(%d)
164NULL
165
166--uppercase NULL--
167string(0) ""
168
169--lowercase null--
170string(0) ""
171
172--lowercase true--
173string(1) "1"
174
175--lowercase false--
176string(0) ""
177
178--uppercase TRUE--
179string(1) "1"
180
181--uppercase FALSE--
182string(0) ""
183
184--empty string DQ--
185string(0) ""
186
187--empty string SQ--
188string(0) ""
189
190--instance of classWithToString--
191string(14) "Class A object"
192
193--instance of classWithoutToString--
194Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, object given, %s(%d)
195NULL
196
197--undefined var--
198string(0) ""
199
200--unset var--
201string(0) ""
202
203--resource--
204Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, resource given, %s(%d)
205NULL
206===DONE===
207