Summary
I'm trying to find a way to change a referenced variable two levels up whilst avoiding Deprecated: Call-time pass-by-reference has been deprecated
Research I've done
I've looked through this and this and it seems like call_user_func_array
can silence the warning however I think I'm missing something.
The Problem
I'm using MongoDB with PHP, the following method belongs to a model and simply checks the schema of the input that is passed into it by reference before saving it.
// $this->collection is the MongoCollection object
public function save(&$entry) {
if( empty($entry) ) return false;
if( !$this->checkSchema($entry) ) $this->throwDbError('Schema violation in `' . get_class($this) . '`');
try { return $this->collection->save(&$entry); } // <---- want to avoid using &
catch (Exception $e) { return $this->throwDbError($e); }
}
MongoCollection::save ($this->collection->save)
will append the _id
field onto $entry
with the new document id. However this change isn't being reflected on the $entry
that is passed into the method above unless I pass it call time by reference. (Essentially I want MongoCollection::save
to be able to modify $entry
two levels up)
All right, that's my best shot at explaining the problem, let me know if you need clarification.