1--TEST--
2By-ref foreach over readonly property
3--FILE--
4<?php
5
6class Test {
7    public readonly int $prop;
8
9    public function init() {
10        $this->prop = 1;
11    }
12}
13
14$test = new Test;
15
16// Okay, as foreach skips over uninitialized properties.
17foreach ($test as &$prop) {}
18
19$test->init();
20
21try {
22    foreach ($test as &$prop) {}
23} catch (Error $e) {
24    echo $e->getMessage(), "\n";
25}
26
27?>
28--EXPECT--
29Cannot acquire reference to readonly property Test::$prop
30