[php-src] Issue #9660: Readonly in aggregate not working

From: Date: Mon, 03 Oct 2022 09:10:25 +0000
Subject: [php-src] Issue #9660: Readonly in aggregate not working
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242511@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9660 Author: roke22 ### Description Readonly is working great in primitive types but not if you try to use in aggregates. This example is not working. Is maybe a documentation error? Is working only with primitives? The following code: ```php <?php class User { public string $username; } class Post { public int $id; public string $title; public string $post; public readonly User $author; public function __construct(User $author) { //Even cloning with $this->author = clone $author; $this->author = $author; } } $user = new User(); $user->username = 'Foo'; $post = new Post($user); echo $post->author->username . PHP_EOL; $post->author->username = 'Bar'; echo $post->author->username . PHP_EOL; ``` Resulted in this output: Foor Bar But I expected this output instead: Error for trying to modify a readonly property ### PHP Version PHP 8.1.11 ### Operating System Debian 10.13

« previous php.bugs (#242511) next »