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