[GIT-PULLS] [php-src] PR #22654: Readonly properties must be re-locked after clone-with
[email protected] (NickSdot)
| Newsgroups | php.git-pulls |
|---|---|
| Message-ID | <vQhKcUYXjto54U4jFQWpVlgauV7yNQ9rKifoB1rrmWI@main.internal.php.net> |
Pull Request: https://github.com/php/php-src/pull/22654
Author: NickSdot
Found this while stealing code for #22588. The following code:
```php
readonly class Test {
public public(set) int $a = 1;
public public(set) int $b = 2;
}
$cloneWith = clone(new Test(), ['a' => 3]); // only a
$cloneWith->b = 4; // why legal?
var_dump($cloneWith);
}
```
Resulted in this output:
```
object(Foo)#2 (2) {
["a"]=>
int(3)
["b"]=>
int(4)
```
But I expected this output instead:
```
Error: Cannot modify readonly property Test::$b
```
cc @TimWolla