3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo implements IteratorAggregate { protected $attributes = []; function __construct(array $arr) { $this->attributes = $arr; } function getIterator(): \Traversable { return new ArrayIterator($this->attributes); } } (new Foo([]))[0];
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Fatal error: Uncaught Error: Cannot use object of type Foo as array in /in/hIimN:18 Stack trace: #0 {main} thrown in /in/hIimN on line 18
Process exited with code 255.

preferences:
73.21 ms | 406 KiB | 5 Q