note 109870 modified in mongocollection.insert by danbrown

From: Date: Fri, 31 Aug 2012 15:37:21 +0000
Subject: note 109870 modified in mongocollection.insert by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190310@lists.php.net to get a copy of this message
If your unfortunate enough and got a task to change behavior of some MongoCollection methods you might encounter some weird behavior. For example this method will not work as expected and $a won&#39;t get _id field assigned:&#13;&#10;&#60;?php&#13;&#10;namespace ns;&#13;&#10;&#13;&#10;class MongoCollection extends \\MongoCollection {&#13;&#10;&#9;function insert(array &#38;$a, array $options = []) {&#13;&#10;&#9;&#9;$res = parent::insert($a, $options);&#13;&#10;&#9;&#9;return $res;&#13;&#10;&#9;}&#13;&#10;}&#13;&#10;?&#62;&#13;&#10;a possible fix:&#13;&#10;&#60;?php&#13;&#10;namespace ns;&#13;&#10;&#13;&#10;class MongoCollection extends \\MongoCollection {&#13;&#10;&#9;function insert(array &#38;$a, array $options = []) {&#13;&#10;&#9;&#9;$b = $a;&#13;&#10;&#9;&#9;$res = parent::insert($b, $options);&#13;&#10;&#9;&#9;$a = $b;&#13;&#10;&#9;&#9;return $res;&#13;&#10;&#9;}&#13;&#10;}&#13;&#10;?&#62; --was-- If your unfortunate enough and got a task to change behavior of some MongoCollection methods you might encounter some weird behavior. For example this method will not work as expected and $a won't get _id field assigned: <?php namespace ns; class MongoCollection extends \MongoCollection { function insert(array &$a, array $options = []) { $res = parent::insert($a, $options); return $res; } } ?> a possible fix: <?php namespace ns; class MongoCollection extends \MongoCollection { function insert(array &$a, array $options = []) { $b = $a; $res = parent::insert($b, $options); $a = $b; return $res; } } http://php.net/manual/en/mongocollection.insert.php

« previous php.notes (#190310) next »