views:

182

answers:

3

I got stuck moving an old website written in php4 to my company's new server that only supports php5. In php4, objects were copied by value, but in php5 it's by reference. Unfortunately for me, the person originally who wrote this site was making objects from others left and right, and now it's causing all sorts of problems. Is there a setting or something that I can change to make php5 copy by value? If not, can I:

A) start writting copy constructors for each object B) do find and replace on every "obj1 = obj2" and make it "obj1 = clone obj2" C) do something else?

Thanks!

A: 

check this page of php manual:
Object cloning
Should help.

Michal M
+2  A: 

Option B is your best bet. PHP5 redesigned object handling in a significant way, so if you have code that is relying specifically on objects being cloned via PHP4 assignment, then unfortunately upgrading the code to the PHP5 method of cloning is the best way to go in my opinion.

zombat
A: 

I think the answer might have to be (B).

I'm not sure it's possible to create copy constructors that perform a clone in PHP (and I don't have a machine on hand to check), but I'd be interested if you can.

therefromhere