I'm in a rut and I'm not sure why I elected for this solution. Something to do with building a simple ORM for MongoDB which has got way more complicated than I imagined. That's not the point though.

Anyway, I've got all of the document data stored in a `protected $_data` variable, and the magic methods `__get`, `__set` etc. all map to this array.

What I'm after is to modify overloaded variables using some of the following code:

```

// Dynamically push using
$model->comments += array('comment' => 'Oh hi there amigo.');

// Alternatively, to push:
array_push($model->comments, array('comment' => 'Oh hi there amigo.'));

// Plus, pop, shift, unshift etc.
array_{verb}($model->comments);

```

Basically, PHP is being a pain and throwing a notification saying:

```
 Indirect modification of overloaded property Model_Blogpost::$comments has no effect

```

I'm not enjoying this one bit. If this logic could go in \_\_set and \_\_get that would remove the need for me to make separate classes for every datatype mongo takes. At least, that's what my logic is saying now.

Does anyone know if something like this is possible? Or do we need to do our own home grown functions to sort this sort of stuff out (as a last resort)?

Thanks in advance, your confused friend.

Edit: 

The PHP version is 5.3.6 and returning by reference as in `&__get` is a bit tricky — here's a quick overview of the code:

<https://github.com/dynamism/Mundo/blob/develop/classes/mundo/object/core.php>

Basically, `__get` calls `get()` to reduce code duplication. `get()` merges the loaded model data (`$_data`) with changed but unsaved model data (`$_changed`) to give the most recent data type.

It does this by flattening the original and changed data into a single dimension array dot using notation and merges the two. Mongo is so loose it's a pain. (FYI: you can use `original()` and `changed()` to get only `$_data` or `$_changed` respectively).

This means that it's not quite as simple as returning part of an array by reference. If that is the only way to do it, though, it looks like it will have to be refactored?