1--TEST--
2References to typed properties with undefined classes
3--FILE--
4<?php
5
6class Test1 {
7    public Foobar $prop;
8    public int $prop2;
9}
10
11$test = new Test1;
12$test->prop2 = 123;
13$ref =& $test->prop2;
14try {
15    $test->prop =& $ref;
16} catch (Error $e) {
17    echo $e->getMessage(), "\n";
18}
19var_dump($test);
20
21class Test2 {
22    public ?Foobar $prop;
23    public ?int $prop2;
24}
25
26$test = new Test2;
27$test->prop2 = null;
28$ref =& $test->prop2;
29$test->prop =& $ref;
30var_dump($test);
31
32?>
33--EXPECT--
34Typed property Test1::$prop must be an instance of Foobar, int used
35object(Test1)#1 (1) {
36  ["prop"]=>
37  uninitialized(Foobar)
38  ["prop2"]=>
39  &int(123)
40}
41object(Test2)#3 (2) {
42  ["prop"]=>
43  &NULL
44  ["prop2"]=>
45  &NULL
46}
47