|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-08-12 16:52 UTC] gerald at croes dot org
[2014-02-09 18:58 UTC] bjori@php.net
-Status: Open
+Status: Not a bug
[2014-02-09 18:58 UTC] bjori@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 11:00:01 2025 UTC |
Description: ------------ I understood that the Mongo drivers are adding the _id property to the given array if the array is given by copy. This is all good. But the Mongo drivers are not checking if the given array is itself a copy of an unmodified array. By forgetting this check, it updates the initial array and its copy. In the given test script, if I add an unset($toInsert['fooProperty']) it works as expected (as the array copy is now effective and different than its origin). Test script: --------------- <?php class EntityObject { private $arData = array(); public function __construct ($initialValue) { $this->setProperty($initialValue); } public function setProperty ($value) { $this->arData['property'] = $value; } public function getProperties () { return $this->arData; } } $entity = new EntityObject('foo'); $mongoClient = new MongoClient(); $toInsert = $entity->getProperties(); $mongoClient->fooDb->fooCollection->insert($toInsert, array('fsync'=>true)); echo "toInsert should be updated with _id \n"; print_r($toInsert); echo "private data should not be updated with _id \n"; print_r($entity->getProperties()); Expected result: ---------------- toInsert should be updated with _id Array ( [property] => foo [_id] => MongoId Object ( [$id] => 52090a28945630cf261e34fc ) ) private data should not be updated with _id Array ( [property] => foo ) Actual result: -------------- toInsert should be updated with _id Array ( [property] => foo [_id] => MongoId Object ( [$id] => 52090a28945630cf261e34fc ) ) private data should not be updated with _id Array ( [property] => foo [_id] => MongoId Object ( [$id] => 52090a28945630cf261e34fc ) )