php/mongodb: how does references work in php?
Kristina Chodorow, the maintainer of the mongoDB php extension, wrote up a nice article in her blog about this issue:
http://www.snailinaturtleneck.com/blog/2011/09/07/more-php-internals-references/
in my opinion it clarifies how things work in php, i still think that references in php are really awkward ...
When you have something like $ref = &$someVar
. $ref
now refers to the value at $someVar
.
EDIT:
The MongoDB Manual at PHP.net says:
Example #1 MongoCollection::insert() _id exampleInserting an object will add an _id field to it, unless it is passed by reference.
<?php$a = array('x' => 1);$collection->insert($a);var_dump($a)$b = array('x' => 1);$ref = &$b;$collection->insert($ref);var_dump($ref);?>