1--TEST--
2Test mb_convert_encoding() function : Circular references
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_convert_encoding') or die("skip mb_convert_encoding() is not available in this build");
7?>
8--FILE--
9<?php
10/*
11 * Test basic functionality of mb_convert_encoding()
12 */
13
14echo "*** Testing mb_convert_encoding() : Circular references ***\n";
15
16//All strings are the same when displayed in their respective encodings
17$sjis_string[] = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
18$sjis_string[] = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
19$tmp = &$sjis_string;
20$sjis_string[] = $tmp;
21
22$jis_string[] = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==');
23$jis_string[] = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==');
24$tmp = &$jis_string;
25$jis_string[] = $tmp;
26
27$euc_jp_string[] = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==');
28$euc_jp_string[] = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==');
29$tmp = &$euc_jp_string;
30$euc_jp_string[] = $tmp;
31
32$utf8_string[] = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
33$utf8_string[] = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
34$tmp = &$utf8_string;
35$utf8_string[] = $tmp;
36
37
38function base64_encode_array($input) {
39    foreach ($input as $var) {
40        if (is_scalar($var))
41            $ret[] = base64_encode($var);
42    }
43    return $ret;
44}
45
46echo "\n-- Convert to JIS --\n";
47echo "JIS encoded string in base64:\n";
48var_dump(base64_encode_array($jis_string));
49echo "Converted Strings:\n";
50var_dump(base64_encode_array(mb_convert_encoding($sjis_string, 'JIS', 'SJIS')));
51var_dump(base64_encode_array(mb_convert_encoding($euc_jp_string, 'JIS', 'EUC-JP')));
52var_dump(base64_encode_array(mb_convert_encoding($utf8_string, 'JIS', 'UTF-8')));
53
54echo "\n-- Convert to EUC-JP --\n";
55echo "EUC-JP encoded string in base64:\n";
56var_dump(base64_encode_array($euc_jp_string));
57echo "Converted Strings:\n";
58var_dump(base64_encode_array(mb_convert_encoding($sjis_string, 'EUC-JP', 'SJIS')));
59var_dump(base64_encode_array(mb_convert_encoding($jis_string, 'EUC-JP', 'JIS')));
60var_dump(base64_encode_array(mb_convert_encoding($utf8_string, 'EUC-JP', 'UTF-8')));
61
62echo "\n-- Convert to SJIS --\n";
63echo "SJIS encoded string in base64:\n";
64var_dump(base64_encode_array($sjis_string));
65echo "Converted Strings:\n";
66var_dump(base64_encode_array(mb_convert_encoding($jis_string, 'SJIS', 'JIS')));
67var_dump(base64_encode_array(mb_convert_encoding($euc_jp_string, 'SJIS', 'EUC-JP')));
68var_dump(base64_encode_array(mb_convert_encoding($utf8_string, 'SJIS', 'UTF-8')));
69
70echo "\n-- Convert to UTF-8 --\n";
71echo "UTF-8 encoded string in base64:\n";
72var_dump(base64_encode_array($utf8_string));
73echo "Converted Strings:\n";
74var_dump(base64_encode_array(mb_convert_encoding($sjis_string, 'UTF-8', 'SJIS')));
75var_dump(base64_encode_array(mb_convert_encoding($jis_string, 'UTF-8', 'JIS')));
76var_dump(base64_encode_array(mb_convert_encoding($euc_jp_string, 'UTF-8', 'EUC-JP')));
77
78echo "Done";
79?>
80--EXPECTF--
81*** Testing mb_convert_encoding() : Circular references ***
82
83-- Convert to JIS --
84JIS encoded string in base64:
85array(2) {
86  [0]=>
87  string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
88  [1]=>
89  string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
90}
91Converted Strings:
92
93Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
94array(2) {
95  [0]=>
96  string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
97  [1]=>
98  string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
99}
100
101Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
102array(2) {
103  [0]=>
104  string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
105  [1]=>
106  string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
107}
108
109Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
110array(2) {
111  [0]=>
112  string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
113  [1]=>
114  string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
115}
116
117-- Convert to EUC-JP --
118EUC-JP encoded string in base64:
119array(2) {
120  [0]=>
121  string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
122  [1]=>
123  string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
124}
125Converted Strings:
126
127Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
128array(2) {
129  [0]=>
130  string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
131  [1]=>
132  string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
133}
134
135Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
136array(2) {
137  [0]=>
138  string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
139  [1]=>
140  string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
141}
142
143Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
144array(2) {
145  [0]=>
146  string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
147  [1]=>
148  string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
149}
150
151-- Convert to SJIS --
152SJIS encoded string in base64:
153array(2) {
154  [0]=>
155  string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
156  [1]=>
157  string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
158}
159Converted Strings:
160
161Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
162array(2) {
163  [0]=>
164  string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
165  [1]=>
166  string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
167}
168
169Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
170array(2) {
171  [0]=>
172  string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
173  [1]=>
174  string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
175}
176
177Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
178array(2) {
179  [0]=>
180  string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
181  [1]=>
182  string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
183}
184
185-- Convert to UTF-8 --
186UTF-8 encoded string in base64:
187array(2) {
188  [0]=>
189  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
190  [1]=>
191  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
192}
193Converted Strings:
194
195Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
196array(2) {
197  [0]=>
198  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
199  [1]=>
200  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
201}
202
203Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
204array(2) {
205  [0]=>
206  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
207  [1]=>
208  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
209}
210
211Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d
212array(2) {
213  [0]=>
214  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
215  [1]=>
216  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
217}
218Done
219