note 109870 modified in mongocollection.insert by danbrown
| From: | danbrown@php.net | 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'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; 	} } ?>
--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