1--TEST--
2foreach by-ref on object with by-val hooked property
3--FILE--
4<?php
5
6class ByVal {
7    public $byRef {
8        &get {
9            $x = 42;
10            return $x;
11        }
12    }
13    public $byVal = 'byValue' {
14        get => $this->byVal;
15        set => $value;
16    }
17}
18
19function test($object) {
20    foreach ($object as $prop => &$value) {
21        var_dump($value);
22    }
23}
24
25try {
26    test(new ByVal);
27} catch (Error $e) {
28    echo $e->getMessage(), "\n";
29}
30
31?>
32--EXPECT--
33int(42)
34Cannot create reference to property ByVal::$byVal
35