1--TEST--
2Assign undef var to typed reference
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6opcache.file_update_protection=0
7opcache.jit_buffer_size=1M
8--FILE--
9<?php
10class Test {
11    public string $x;
12}
13
14function test_simple_res() {
15    $test = new Test;
16    $test->x = "";
17    $r =& $test->x;
18    var_dump($r = $v);
19}
20
21function test_simple_nores() {
22    $test = new Test;
23    $test->x = "";
24    $r =& $test->x;
25    $r = $v;
26}
27
28function test_dim_res() {
29    $test = new Test;
30    $test->x = "";
31    $a[0] =& $test->x;
32    var_dump($a[0] = $v);
33}
34
35function test_dim_nores() {
36    $test = new Test;
37    $test->x = "";
38    $a[0] =& $test->x;
39    $a[0] = $v;
40}
41
42function test_obj_res() {
43    $test = new Test;
44    $test->x = "";
45    $o = new stdClass;
46    $o->p =& $test->x;
47    var_dump($o->p = $v);
48}
49
50function test_obj_nores() {
51    $test = new Test;
52    $test->x = "";
53    $o = new stdClass;
54    $o->p =& $test->x;
55    $o->p = $v;
56}
57
58try {
59    test_simple_res();
60} catch (TypeError $e) {
61    echo $e->getMessage(), "\n";
62}
63try {
64    test_simple_nores();
65} catch (TypeError $e) {
66    echo $e->getMessage(), "\n";
67}
68try {
69    test_dim_res();
70} catch (TypeError $e) {
71    echo $e->getMessage(), "\n";
72}
73try {
74    test_dim_nores();
75} catch (TypeError $e) {
76    echo $e->getMessage(), "\n";
77}
78try {
79    test_obj_res();
80} catch (TypeError $e) {
81    echo $e->getMessage(), "\n";
82}
83try {
84    test_obj_nores();
85} catch (TypeError $e) {
86    echo $e->getMessage(), "\n";
87}
88
89?>
90--EXPECTF--
91Warning: Undefined variable $v in %s on line %d
92Cannot assign null to reference held by property Test::$x of type string
93
94Warning: Undefined variable $v in %s on line %d
95Cannot assign null to reference held by property Test::$x of type string
96
97Warning: Undefined variable $v in %s on line %d
98Cannot assign null to reference held by property Test::$x of type string
99
100Warning: Undefined variable $v in %s on line %d
101Cannot assign null to reference held by property Test::$x of type string
102
103Warning: Undefined variable $v in %s on line %d
104Cannot assign null to reference held by property Test::$x of type string
105
106Warning: Undefined variable $v in %s on line %d
107Cannot assign null to reference held by property Test::$x of type string
108