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