1--TEST--
2Assignments to references that are held by properties with union types
3--FILE--
4<?php
5
6class Test {
7    public int|string $x;
8    public float|string $y;
9}
10
11$test = new Test;
12$r = "foobar";
13$test->x =& $r;
14$test->y =& $r;
15
16$v = 42;
17try {
18    $r = $v;
19} catch (TypeError $e) {
20    echo $e->getMessage(), "\n";
21}
22var_dump($r, $v);
23
24$v = 42.0;
25try {
26    $r = $v;
27} catch (TypeError $e) {
28    echo $e->getMessage(), "\n";
29}
30var_dump($r, $v);
31
32unset($r, $test->x, $test->y);
33
34$test->x = 42;
35try {
36    $test->y =& $test->x;
37} catch (TypeError $e) {
38    echo $e->getMessage(), "\n";
39}
40
41unset($test->x, $test->y);
42
43$test->y = 42.0;
44try {
45    $test->x =& $test->y;
46} catch (TypeError $e) {
47    echo $e->getMessage(), "\n";
48}
49
50?>
51--EXPECT--
52Cannot assign int to reference held by property Test::$x of type string|int and property Test::$y of type string|float, as this would result in an inconsistent type conversion
53string(6) "foobar"
54int(42)
55Cannot assign float to reference held by property Test::$x of type string|int and property Test::$y of type string|float, as this would result in an inconsistent type conversion
56string(6) "foobar"
57float(42)
58Reference with value of type int held by property Test::$x of type string|int is not compatible with property Test::$y of type string|float
59Reference with value of type float held by property Test::$y of type string|float is not compatible with property Test::$x of type string|int
60