mirror of
https://github.com/php/php-src.git
synced 2026-04-29 11:13:36 +02:00
46ee0fb304
Indirect modification isn't allowed in __construct() because it allows references to leak, so it doesn't make much sense to allow it in __clone().
34 lines
611 B
PHP
34 lines
611 B
PHP
--TEST--
|
|
__clone() cannot indirectly modify unlocked readonly properties
|
|
--FILE--
|
|
<?php
|
|
|
|
class Foo {
|
|
public function __construct(
|
|
public readonly array $bar
|
|
) {}
|
|
|
|
public function __clone()
|
|
{
|
|
$this->bar['bar'] = 'bar';
|
|
}
|
|
}
|
|
|
|
$foo = new Foo([]);
|
|
// First call fills the cache slot
|
|
try {
|
|
var_dump(clone $foo);
|
|
} catch (Error $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
try {
|
|
var_dump(clone $foo);
|
|
} catch (Error $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
Cannot indirectly modify readonly property Foo::$bar
|
|
Cannot indirectly modify readonly property Foo::$bar
|