note 112414 added to mongoid.construct

From: Date: Fri, 14 Jun 2013 09:51:20 +0000
Subject: note 112414 added to mongoid.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-195206@lists.php.net to get a copy of this message
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); } } } ?> ---- Server IP: 69.147.83.199 Probable Submitter: 176.73.174.4 ---- Manual Page -- http://php.net/manual/en/mongoid.construct.php Edit -- https://master.php.net/note/edit/112414 Del: integrated -- https://master.php.net/note/delete/112414/integrated Del: useless -- https://master.php.net/note/delete/112414/useless Del: bad code -- https://master.php.net/note/delete/112414/bad+code Del: spam -- https://master.php.net/note/delete/112414/spam Del: non-english -- https://master.php.net/note/delete/112414/non-english Del: in docs -- https://master.php.net/note/delete/112414/in+docs Del: other reasons-- https://master.php.net/note/delete/112414 Reject -- https://master.php.net/note/reject/112414 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195206) next »