Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-1690

MongoDB\Driver\Cursor must implement IteratorAggregate for PHP 8

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      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.

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: