1--TEST--
2Asymmetric visibility private(set)
3--FILE--
4<?php
5
6class Foo {
7    public private(set) string $bar = 'bar';
8
9    private(set) string $baz = 'baz';
10
11    public function setBar($bar) {
12        $this->bar = $bar;
13    }
14
15    public function setBaz($baz) {
16        $this->baz = $baz;
17    }
18}
19
20class FooChild extends Foo {
21    public function modifyBar($bar) {
22        $this->bar = $bar;
23    }
24}
25
26$foo = new Foo();
27var_dump($foo->bar);
28
29try {
30    $foo->bar = 'baz';
31} catch (Error $e) {
32    echo $e->getMessage(), "\n";
33}
34
35$foo->setBar('baz');
36var_dump($foo->bar);
37
38try {
39    $foo->baz = 'baz2';
40} catch (Error $e) {
41    echo $e->getMessage(), "\n";
42}
43
44$foo->setBaz('baz2');
45var_dump($foo->baz);
46
47$child = new FooChild();
48try {
49    $child->modifyBar('baz');
50} catch (Error $e) {
51    echo $e->getMessage(), "\n";
52}
53
54?>
55--EXPECT--
56string(3) "bar"
57Cannot modify private(set) property Foo::$bar from global scope
58string(3) "baz"
59Cannot modify private(set) property Foo::$baz from global scope
60string(4) "baz2"
61Cannot modify private(set) property Foo::$bar from scope FooChild
62