Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Can iterator_to_array() throw an exception on a MongoCursor

Can using iterator_to_array() on a MongoCursor instance throw an exception in PHP 5.3? In other words, do I need to wrap iterator_to_array() calls on MongoCursor instances in try-catch statements or not?

e.g.,

$mongo = new Mongo();
$mongo_db = $mongo['my_database'];
$mongo_coll = $mongo_db['my_collection'];

// This

$cursor = $mongo_coll->find();
$documents = iterator_to_array($cursor);

// Versus this.

$cursor = $mongo_coll->find();
try {
    $documents = iterator_to_array($cursor);
} catch (Exception $e) {
    //...
}
like image 775
Uyghur Lives Matter Avatar asked Feb 20 '26 08:02

Uyghur Lives Matter


1 Answers

iterator_to_array() can throw exceptions because it calls next().

like image 77
pingw33n Avatar answered Feb 22 '26 22:02

pingw33n