hello,
i asked this in the mongodb user-group, but was not satisfied with the answer, so -- maybe someone at stackoverflow can enlighten me:
EDIT:
i've re-written my question, because apparently it wasn't clear, what was happening -- please try my test-code before answering. thanks!
<?php
// test: a
$data = array('x' => 1);
function a(&$data) {
$m = new mongo();
$c = $m->selectDB('test')->selectCollection('test');
$c->insert($data);
}
a($data);
print_r($data);
// test: b
$data = array('x' => 1);
function b($data) {
$m = new mongo();
$c = $m->selectDB('test')->selectCollection('test');
$c->insert($data);
}
b($data);
print_r($data);
// test: c
$data = array('x' => 1);
function c(&$data) {
$data['_id'] = new MongoId();
}
c($data);
print_r($data);
// test: d
$data = array('x' => 1);
function d($data) {
$data['_id'] = new MongoId();
}
d($data);
print_r($data);
?>
output:
Array
(
[x] => 1
)
Array
(
[x] => 1
[_id] => MongoId Object
(
)
)
Array
(
[x] => 1
[_id] => MongoId Object
(
)
)
Array
(
[x] => 1
)
my question: why does pass-by-reference apparently work different for mongo insert compared to my plain php function call?
thanks!