1--TEST-- 2Readonly property modification error through ArrayIterator 3--FILE-- 4<?php 5class A implements IteratorAggregate { 6 function __construct( 7 public readonly string $foo = 'bar' 8 ) {} 9 10 function getIterator(): Traversable { 11 return new ArrayIterator($this); 12 } 13} 14 15$obj = new A; 16 17try { 18 foreach ($obj as $k => &$v) {} 19} catch (Throwable $e) { 20 echo $e->getMessage(), "\n"; 21} 22 23var_dump($obj); 24?> 25--EXPECT-- 26Cannot acquire reference to readonly property A::$foo 27object(A)#1 (1) { 28 ["foo"]=> 29 string(3) "bar" 30} 31