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(); $_id = new MongoId(null); $_id = new MongoId("invalid id"); ?>
<?php
$_id = "invalid id";
try {
$_id = new MongoId($_id);
} catch (MongoException $ex) {
$_id = new MongoId();
}
?>
<?php
class SafeMongoId extends MongoId {
public function __construct($id=null) {
try {
parent::__construct($id);
} catch (MongoException $ex) {
parent::__construct(null);
}
}
}
?>