Hi!
Ok, this is the thing. I got a class, which stores it's content as an array of other objects. You can call a function of this class, which creates a new object, stores it in it's internal array, and passes the object to the caller. My problem is, though, that this is supposed to be a library, more-or-less self contained, where the person using it, doesn't have to care about hard-copies vs. references, it should all be done for him. So I wondered, is there a way to send a reference of an object back to the caller, without the caller needing to use the & sign??
I know this code works:
// in the library...
class bla {
function &newSome()
{
$some = new OtherObject();
return $some;
}
}
// in the users file...
$instance = new bla();
$myRef = &$instance->newSome();
...but it leaves a bit of stress on the one using the library to know when to use and when not to use the & sign, as if he doesn't use it in the example above, he'll get a copy of the same object the class stores, and thus the class won't keep up with the changes the user makes to his copy of the newly created OtherObject instance...
Help, please 🙂)
TiA