Why Model implementing IterableAggregate?

Model in Yii 2 implements PHP interface IteratorAggregate, which extends Traversable. Which means all ActiveRecords in Yii can be traversed? Does that make sense?

I’m bring it up, because phpstan complains about the typing if you do this:

/** @var MyModel|null */
$mymodel = MyModel::findOne();

because it wants MyModel<Foo> (since it’s iterable).

1 Like