At 11:26 PM -0700 3/16/05, Luke Palmer wrote:
> For each of the above cases, is a copy of or a reference to the
 attribute returned?  For each, will the calling code be able to
 modify $obj's attributes by modifying the return values, or not?

Well if you're making accessors, why the heck are you making them private? But I can't really answer your question, because it depends on how you write the accessors.

I am writing accessors to mediate with the attributes, which are all private, and whose implementation may change over time. What I want, in the normal case, is that calling code which invokes my methods will get a copy of attributes which it can modify, that won't affect the original attribute values.


When I last asked a related question here, I was told that simply returning an attribute will allow the caller to modify the original attribute by default. I wanted to make sure this didn't happen. It is possible that there was a misunderstanding regarding the previous question, and the default action is in fact a copy.

-- Darren Duncan

Reply via email to