Due to Recent changes.
* [PHP-554] - MongoId should not get constructed when passing in an invalid ID.
Constructor will throw an exception when passing invalid ID.
<?php
$_id = new MongoId(); //Generates new ID
$_id = new MongoId(null); //Generates new ID
$_id = new MongoId("invalid id"); //throws MongoException
?>
<?php
//Revert to old behaviour
$_id = "invalid id";
try {
$_id = new MongoId($_id);
} catch (MongoException $ex) {
$_id = new MongoId();
}
?>
<?php
//Nifty hack
class SafeMongoId extends MongoId {
public function __construct($id=null) {
try {
parent::__construct($id);
} catch (MongoException $ex) {
parent::__construct(null);
}
}
}
?>