1
0
mirror of https://github.com/php/php-src.git synced 2026-04-29 11:13:36 +02:00
Files
Ilija Tovilo 46ee0fb304 Disallow indirect modification on readonly properties within __clone() (#15012)
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().
2024-08-09 11:56:16 +02:00

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