1--TEST--
2Asymmetric visibility with readonly
3--FILE--
4<?php
5
6class P {
7    public readonly int $pDefault;
8    public private(set) readonly int $pPrivate;
9    public protected(set) readonly int $pProtected;
10    public public(set) readonly int $pPublic;
11
12    public function __construct() {
13        $this->pDefault = 1;
14        $this->pPrivate = 1;
15        $this->pProtected = 1;
16        $this->pPublic = 1;
17    }
18}
19
20class C extends P {
21    public function __construct() {
22        $this->pDefault = 1;
23        try {
24            $this->pPrivate = 1;
25        } catch (Error $e) {
26            echo $e->getMessage(), "\n";
27        }
28        $this->pProtected = 1;
29        $this->pPublic = 1;
30    }
31}
32
33function test() {
34    $p = new ReflectionClass(P::class)->newInstanceWithoutConstructor();
35    try {
36        $p->pDefault = 1;
37    } catch (Error $e) {
38        echo $e->getMessage(), "\n";
39    }
40    try {
41        $p->pPrivate = 1;
42    } catch (Error $e) {
43        echo $e->getMessage(), "\n";
44    }
45    try {
46        $p->pProtected = 1;
47    } catch (Error $e) {
48        echo $e->getMessage(), "\n";
49    }
50    $p->pPublic = 1;
51}
52
53new P();
54new C();
55test();
56
57?>
58--EXPECT--
59Cannot modify private(set) property P::$pPrivate from scope C
60Cannot modify protected(set) readonly property P::$pDefault from global scope
61Cannot modify private(set) property P::$pPrivate from global scope
62Cannot modify protected(set) readonly property P::$pProtected from global scope
63