xref: /PHP-8.3/ext/mbstring/tests/gh16261.phpt (revision bf70d9ba)
1--TEST--
2GH-16261 (Reference invariant broken in mb_convert_variables())
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7class Test {
8    public string $x;
9    public string $y;
10    public array $z;
11}
12$test = new Test;
13$ref = "hello";
14$ref2 = "world";
15$ref3 = [&$ref2];
16$test->x =& $ref;
17$test->z =& $ref3;
18mb_convert_variables("EUC-JP", "Shift_JIS", $test);
19
20class Test2 {
21    public function __construct(public string $x) {}
22}
23$test2 = new Test2("foo");
24
25mb_convert_variables("EUC-JP", "Shift_JIS", $test->x);
26
27var_dump($test, $test2);
28?>
29--EXPECT--
30object(Test)#1 (2) {
31  ["x"]=>
32  string(5) "hello"
33  ["y"]=>
34  uninitialized(string)
35  ["z"]=>
36  &array(1) {
37    [0]=>
38    string(5) "world"
39  }
40}
41object(Test2)#2 (1) {
42  ["x"]=>
43  string(3) "foo"
44}
45