1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
--TEST--
Test that readonly properties cannot be reassigned by invoking the __clone() method directly
--FILE--
<?php
class Foo
{
public function __construct(
public readonly int $bar
) {}
public function __clone()
{
$this->bar = 1;
}
}
$foo = new Foo(0);
var_dump($foo);
try {
$foo->__clone();
} catch (Error $e) {
echo $e->getMessage() . "\n";
}
try {
$foo->__clone();
} catch (Error $e) {
echo $e->getMessage() . "\n";
}
var_dump($foo);
?>
--EXPECTF--
object(Foo)#%d (%d) {
["bar"]=>
int(0)
}
Cannot modify readonly property Foo::$bar
Cannot modify readonly property Foo::$bar
object(Foo)#%d (%d) {
["bar"]=>
int(0)
}
|