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