<?php
abstract class Foo implements Traversable {
}
class Bar extends Foo implements IteratorAggregate {
public function getIterator() {
return new ArrayIterator([1, 2, 3]);
}
}
$b = new Bar;
foreach ($b as $value) {
var_dump($value);
}
Deprecated: Return type of Bar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/3hhjJ on line 7
int(1)
int(2)
int(3)
Fatal error: Class Foo must implement interface Traversable as part of either Iterator or IteratorAggregate in Unknown on line 0
Process exited with code 255.