[php-src] PR #22654: Readonly properties must be re-locked after clone-with
| From: | NickSdot | Date: | Thu, 09 Jul 2026 16:39:48 +0000 |
| Subject: | [php-src] PR #22654: Readonly properties must be re-locked after clone-with | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-36934@lists.php.net to get a copy of this message | ||
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