Call to undefined method MongoDB\Driver\Cursor::current()

Viewed 622

I get in PHP this error:

Fatal error: Uncaught Error: Call to undefined method MongoDB\Driver\Cursor::current()`.

Which seems to be in contradiction with the documentation.

I can show my code but, well, I call the method current() for a MongoDB cursor.

1 Answers

This functionality was just added a few weeks ago:

MongoDB\Driver\Cursor has historically only implemented Traversable and provided an internal iterator (not to be to the Iterator userland class). PHP 8 required that we implement either Iterator or IteratorAggregate directly (PHPC-1690), although PHP also provides an internal iterator for extensions to make that easier.

That said, we should consider providing a proper Iterator implementation on the Cursor to remove our reliance on the internal iterator class for PHP 8 and present a consistent API for all supported versions.

https://jira.mongodb.org/browse/PHPC-1691 (Resolved 4 November 2020)

Ensure any packages you have are up-to-date, or install from source if necessary.

Related