1--TEST--
2Foreach by reference on nullsafe
3--FILE--
4<?php
5
6class Foo {
7    public $bar;
8}
9
10$foo = new Foo();
11
12foreach ($foo?->bar as &$value) {
13    var_dump($value);
14}
15
16// Don't convert $foo->bar into a reference.
17$foo->bar = [42];
18foreach ($foo?->bar as &$value) {
19    var_dump($value);
20    $value++;
21}
22var_dump($foo->bar);
23
24// But respect interior references.
25$ref =& $foo->bar[0];
26foreach ($foo?->bar as &$value) {
27    var_dump($value);
28    $value++;
29}
30var_dump($foo->bar);
31
32?>
33--EXPECTF--
34Warning: foreach() argument must be of type array|object, null given in %s on line %d
35int(42)
36array(1) {
37  [0]=>
38  int(42)
39}
40int(42)
41array(1) {
42  [0]=>
43  &int(43)
44}
45