Question: I have an object that I'm passing in a method call. Say I'm using a language that only allows you to pass objects by reference, like Java or PHP. If the method makes changes to the object, it will affect the caller. I don't want this to happen. So it seems like I need to make a copy of the object.

My question is: whose responsibility is it to clone the object? The caller, before it calls the method? Or the callee, before it changes the object?

EDIT: Just to clarify, I want this to be part of the contract of this method -- that it never modifies the original object. So it seems like it should be up to the method to make the copy. But then the caller has no protection from a method that doesn't do this properly. I guess that's acceptable -- the only other alternative seems to be to have this built into the language.

Answer: 
The caller. Because, sometimes you want to make changes to the objects themselves and other times to a copy.

Although, I consider it a bad practice for callee to modify passed objects (at least in object oriented languages). This can cause many unwanted side effects.

(after your) EDIT: In that case it is callee's responsibility to enforce the contract, so there are two options:

* The callee simply does not modify the object
* or the callee copies the object and works with the copy afterwards
My first reaction would be that it is the caller's responsibility, but I think it actually depends.

It depends on the contract defined between the two methods. The method that is making changes should explicitly identify that fact and let the caller make the decision. OR, The method that is making the changes should explicitly identify that it will NOT make any changes to the passed object and then it would be responsible for making the copy.