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