1--TEST--
2Test that there can be no side-effect when a readonly property modification fails
3--FILE--
4<?php
5
6class Foo {
7    public function __construct(
8        public readonly string $bar
9    ) {}
10
11    public function write() {
12        $this->bar = new S();
13    }
14}
15
16class S {
17    public function __toString() {
18        var_dump("Side-effect in __toString()");
19        return "";
20    }
21}
22
23$foo = new Foo("");
24
25try {
26    $foo->write();
27} catch (Error $e) {
28    echo $e->getMessage() . "\n";
29}
30
31?>
32--EXPECT--
33Cannot modify readonly property Foo::$bar
34