1--TEST--
2Readonly nested variations
3--FILE--
4<?php
5
6class Inner {
7    public int $prop = 1;
8    public array $array = [];
9}
10
11class Test {
12    public readonly Inner $prop;
13
14    public function init() {
15        $this->prop = new Inner();
16    }
17}
18
19function r($test) {
20    echo $test->prop->prop;
21}
22
23function w($test) {
24    $test->prop->prop = 0;
25    echo 'done';
26}
27
28function rw($test) {
29    $test->prop->prop += 1;
30    echo 'done';
31}
32
33function im($test) {
34    $test->prop->array[] = 1;
35    echo 'done';
36}
37
38function is($test) {
39    echo (int) isset($test->prop->prop);
40}
41
42function us($test) {
43    unset($test->prop->prop);
44    echo 'done';
45}
46
47foreach ([true, false] as $init) {
48    foreach (['r', 'w', 'rw', 'im', 'is', 'us'] as $op) {
49        $test = new Test();
50        if ($init) {
51            $test->init();
52        }
53
54        echo 'Init: ' . ((int) $init) . ', op: ' . $op . ": ";
55        try {
56            $op($test);
57        } catch (Error $e) {
58            echo $e->getMessage();
59        }
60        echo "\n";
61    }
62}
63
64?>
65--EXPECT--
66Init: 1, op: r: 1
67Init: 1, op: w: done
68Init: 1, op: rw: done
69Init: 1, op: im: done
70Init: 1, op: is: 1
71Init: 1, op: us: done
72Init: 0, op: r: Typed property Test::$prop must not be accessed before initialization
73Init: 0, op: w: Cannot indirectly modify readonly property Test::$prop
74Init: 0, op: rw: Typed property Test::$prop must not be accessed before initialization
75Init: 0, op: im: Cannot indirectly modify readonly property Test::$prop
76Init: 0, op: is: 0
77Init: 0, op: us: done
78