3v4l.org

run code in 500+ PHP versions simultaneously
<?php class A implements IteratorAggregate { function __construct( public string $foo = 'bar' ) {} function getIterator(): Traversable { return new ArrayIterator($this); } } $obj = new A; foreach ($obj as $k => &$v) { $v = 42; } var_dump($obj);
Output for 8.5.0 - 8.5.13, 8.6.0
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in /in/V7sci on line 9 object(A)#1 (1) { ["foo"]=> &string(2) "42" }
Output for 8.2.5 - 8.2.36, 8.3.0 - 8.3.37, 8.4.1 - 8.4.28
object(A)#1 (1) { ["foo"]=> &string(2) "42" }
Output for 8.2.0 - 8.2.4
object(A)#1 (1) { ["foo"]=> &int(42) }

preferences:
15.52 ms | 1169 KiB | 6 Q