File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Zend/tests/readonly_props Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ Test that readonly properties cannot be reassigned by invoking the __clone() method directly
3+ --FILE--
4+ <?php
5+
6+ class Foo
7+ {
8+ public function __construct (
9+ public readonly int $ bar
10+ ) {}
11+
12+ public function __clone ()
13+ {
14+ $ this ->bar = 1 ;
15+ }
16+ }
17+
18+ $ foo = new Foo (0 );
19+
20+ var_dump ($ foo );
21+
22+ try {
23+ $ foo ->__clone ();
24+ } catch (Error $ e ) {
25+ echo $ e ->getMessage () . "\n" ;
26+ }
27+
28+ try {
29+ $ foo ->__clone ();
30+ } catch (Error $ e ) {
31+ echo $ e ->getMessage () . "\n" ;
32+ }
33+
34+ var_dump ($ foo );
35+
36+ ?>
37+ --EXPECTF--
38+ object(Foo)#%d (%d) {
39+ ["bar"]=>
40+ int(0)
41+ }
42+ Cannot modify readonly property Foo::$bar
43+ Cannot modify readonly property Foo::$bar
44+ object(Foo)#%d (%d) {
45+ ["bar"]=>
46+ int(0)
47+ }
You can’t perform that action at this time.
0 commit comments