1--TEST--
2Test iconv_set_encoding() function : basic functionality
3--SKIPIF--
4<?php
5extension_loaded('iconv') or die('skip');
6function_exists('iconv_set_encoding') or die("skip iconv_set_encoding() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : bool iconv_set_encoding(string type, string charset)
11 * Description: Sets internal encoding and output encoding for ob_iconv_handler()
12 * Source code: ext/iconv/iconv.c
13 */
14
15/*
16 * Test Error functionality of iconv_get_encoding
17 */
18
19echo "*** Testing iconv_set_encoding() : error functionality ***\n";
20
21//get an unset variable
22$unset_var = 10;
23unset ($unset_var);
24
25// get a class
26class classA
27{
28  public function __toString() {
29    return "UTF-8";
30  }
31}
32
33// heredoc string
34$heredoc = <<<EOT
35Nothing
36EOT;
37
38// get a resource variable
39$fp = fopen(__FILE__, "r");
40
41// unexpected values to be passed to $encoding argument
42$inputs = array(
43
44       // int data
45/*1*/  0,
46       1,
47       12345,
48       -2345,
49
50       // float data
51/*5*/  10.5,
52       -10.5,
53       12.3456789000e10,
54       12.3456789000E-10,
55       .5,
56
57       // null data
58/*10*/ NULL,
59       null,
60
61       // boolean data
62/*12*/ true,
63       false,
64       TRUE,
65       FALSE,
66
67       // empty data
68/*16*/ "",
69       '',
70
71       // invalid string data
72/*18*/ "Nothing",
73       'Nothing',
74       $heredoc,
75
76       // object data
77/*21*/ new classA(),
78
79       // undefined data
80/*22*/ @$undefined_var,
81
82       // unset data
83/*23*/ @$unset_var,
84
85       // resource variable
86/*24*/ $fp
87);
88
89// loop through each element of $inputs to check the behavior of mb_regex_encoding()
90$iterator = 1;
91foreach($inputs as $input) {
92  echo "\n-- Iteration $iterator --\n";
93  var_dump( iconv_set_encoding($input, "UTF-8") );
94  $iterator++;
95};
96
97fclose($fp);
98
99echo "Done";
100?>
101--EXPECTF--
102*** Testing iconv_set_encoding() : error functionality ***
103
104-- Iteration 1 --
105bool(false)
106
107-- Iteration 2 --
108bool(false)
109
110-- Iteration 3 --
111bool(false)
112
113-- Iteration 4 --
114bool(false)
115
116-- Iteration 5 --
117bool(false)
118
119-- Iteration 6 --
120bool(false)
121
122-- Iteration 7 --
123bool(false)
124
125-- Iteration 8 --
126bool(false)
127
128-- Iteration 9 --
129bool(false)
130
131-- Iteration 10 --
132bool(false)
133
134-- Iteration 11 --
135bool(false)
136
137-- Iteration 12 --
138bool(false)
139
140-- Iteration 13 --
141bool(false)
142
143-- Iteration 14 --
144bool(false)
145
146-- Iteration 15 --
147bool(false)
148
149-- Iteration 16 --
150bool(false)
151
152-- Iteration 17 --
153bool(false)
154
155-- Iteration 18 --
156bool(false)
157
158-- Iteration 19 --
159bool(false)
160
161-- Iteration 20 --
162bool(false)
163
164-- Iteration 21 --
165bool(false)
166
167-- Iteration 22 --
168bool(false)
169
170-- Iteration 23 --
171bool(false)
172
173-- Iteration 24 --
174
175Warning: iconv_set_encoding() expects parameter 1 to be string, resource given in %s on line %d
176NULL
177Done
178