MongoDB\Driver\Cursor::current() returns nothing but it should

Viewed 96

I'm on PHP 8.

var_dump(get_class($usernameInDb)); returns string(21) "MongoDB\Driver\Cursor"

var_dump($usernameInDb); shows that there is a document.

$avirer = $usernameInDb->current(); doesn't cause a PHP error in error.log.

var_dump($avirer); returns int(8) string(26) "Undefined variable: avirer"

It seems to me in contradiction with the documentation

Does someone know what's going on ?

1 Answers

This should be a fixed bug.

$avirer is undefined because $usernameInDb->current() did not handle invalid positions that caused the $avirer to be in an invalid state.

If you do something like

var_dump($cursor->current());
echo gettype($cursor->current());

The output will be

UNKNOWN:0
unknown type

Which is how var_dump and gettype handle Unknown data types.

Related