xref: /PHP-7.4/ext/mbstring/tests/bug81011.phpt (revision 0cafd53d)
1--TEST--
2Bug #81011 (mb_convert_encoding removes references from arrays)
3--SKIPIF--
4<?php
5if (!extension_loaded('mbstring')) die("skip mbstring extension not available");
6?>
7--FILE--
8<?php
9$array = [
10    'ads' => [
11        123 => ['name' => 'this', 'id' => 444],
12        234 => ['name' => 'that', 'id' => 555],
13    ],
14    'other' => ['one', 'two']
15    ];
16
17// we modify array elements using reference
18foreach( $array['ads'] as &$ad ){
19    $ad['premium'] = (int)($ad['id'] == 555);
20}
21
22var_dump($array);
23var_dump(mb_convert_encoding($array, 'UTF-8', 'UTF-8'));
24?>
25--EXPECT--
26array(2) {
27  ["ads"]=>
28  array(2) {
29    [123]=>
30    array(3) {
31      ["name"]=>
32      string(4) "this"
33      ["id"]=>
34      int(444)
35      ["premium"]=>
36      int(0)
37    }
38    [234]=>
39    &array(3) {
40      ["name"]=>
41      string(4) "that"
42      ["id"]=>
43      int(555)
44      ["premium"]=>
45      int(1)
46    }
47  }
48  ["other"]=>
49  array(2) {
50    [0]=>
51    string(3) "one"
52    [1]=>
53    string(3) "two"
54  }
55}
56array(2) {
57  ["ads"]=>
58  array(2) {
59    [123]=>
60    array(3) {
61      ["name"]=>
62      string(4) "this"
63      ["id"]=>
64      int(444)
65      ["premium"]=>
66      int(0)
67    }
68    [234]=>
69    array(3) {
70      ["name"]=>
71      string(4) "that"
72      ["id"]=>
73      int(555)
74      ["premium"]=>
75      int(1)
76    }
77  }
78  ["other"]=>
79  array(2) {
80    [0]=>
81    string(3) "one"
82    [1]=>
83    string(3) "two"
84  }
85}
86