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
If not changing the object is part of the method contract, the only possibility is having the copy made inside the method. Otherwise you are lying to your client.

The fact that you actually need to modify an object exactly like the one given to you is just an implementation detail that should not put a burden on the caller. In fact, he does not even need to have visibility of that.