1--TEST--
2Test typed properties passed to typed function
3--FILE--
4<?php
5$foo = new class {
6	public ?int $bar = 42;
7	public int $baz;
8
9	public function &getIterator() {
10		foreach (['1', &$this->bar] as &$item) {
11			yield $item;
12		}
13	}
14};
15
16function foo(?int &$a) {
17	var_dump($a);
18	$a = null;
19}
20
21foo($foo->bar);
22
23try {
24	$foo->baz = &$foo->bar;
25} catch (Error $e) { echo $e->getMessage(), "\n"; }
26$foo->bar = 10;
27
28foreach ($foo->getIterator() as &$item) {
29	$foo->baz = &$item;
30	var_dump($foo->baz);
31}
32
33try {
34	foo($foo->bar);
35} catch (Error $e) { echo $e->getMessage(), "\n"; }
36
37var_dump($foo);
38?>
39--EXPECT--
40int(42)
41Typed property class@anonymous::$baz must be int, null used
42int(1)
43int(10)
44int(10)
45Cannot assign null to reference held by property class@anonymous::$baz of type int
46object(class@anonymous)#1 (2) {
47  ["bar"]=>
48  &int(10)
49  ["baz"]=>
50  &int(10)
51}
52