[php-src] Issue #10844: modify readonly class property with reference

From: Date: Mon, 13 Mar 2023 14:42:21 +0000
Subject: [php-src] Issue #10844: modify readonly class property with reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243905@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10844 Author: varrg ### Description The following code: ```php <?php readonly class A implements IteratorAggregate { function __construct(readonly public string $foo = 'bar') {} function getIterator() : Traversable { return new ArrayIterator($this); } } $obj = new A; //$obj->foo = 'baz'; // expected fatal error //$prop = &$obj->foo; // expected fatal error foreach ($obj as $k => &$v) { $v = 'baz'; } var_dump($obj); ``` Resulted in this output: ``` object(A)#1 (1) { ["foo"]=> &string(3) "baz" } ``` But I expected this output instead: ``` Fatal error: Uncaught Error: Cannot modify readonly property A::$foo ``` ### PHP Version 8.2.3 ### Operating System _No response_

« previous php.bugs (#243905) next »