PHP 8 now longer allows userland-exposed classes to only implement Traversable, as Cursor currently does. Per https://github.com/php/php-src/blob/master/UPGRADING.INTERNALS:
Just for for userland classes, it is no longer allowed to implement only the Traversable interface. Instead, it is necessary to implement either Iterator or IteratorAggregate. You can do the latter by implementing zend_ce_aggregate and providing the following method implementation: ZEND_METHOD(MyClass, getIterator) { ZEND_PARSE_PARAMETERS_NONE(); zend_create_internal_iterator_zval(return_value, ZEND_THIS); }
We will add this method and implement IteratorAggregate for PHP 8 only as an undocumented change (since PHP 8's InternalIterator itself is undocumented). Separately, we can consider changing Cursor to implement Iterator directly and provide a consistent API for all supported PHP versions.
- related to
-
PHPC-1691 Iterator implementation for MongoDB\Driver\Cursor
- Closed
-
PHPLIB-594 Ensure ChangeStream is compatible with PHP 8's InternalIterator
- Closed