1--TEST--
2Use array append as initialization
3--FILE--
4<?php
5
6class C {
7    public readonly array $a;
8
9    public function init() {
10        $this->a[] = 1;
11        var_dump($this->a);
12    }
13}
14
15
16function init() {
17    $c = new C;
18    $c->a[] = 1;
19    var_dump($c->a);
20}
21
22try {
23    (new C)->init();
24} catch (Error $e) {
25    echo $e->getMessage(), "\n";
26}
27
28try {
29    init();
30} catch (Error $e) {
31    echo $e->getMessage(), "\n";
32}
33
34?>
35--EXPECT--
36Cannot indirectly modify readonly property C::$a
37Cannot indirectly modify readonly property C::$a
38