iterator_to_array()实例上使用MongoCursor是否会在php 5.3中引发异常?换句话说,我是否需要在try-catch语句中包装对iterator_to_array()实例的MongoCursor调用?
例如。,

$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) {
    //...
}

最佳答案

iterator_to_array()可以引发异常,因为它调用next()

10-06 14:49