Is there a PHP5 parameter to copy objects by value?

I got stuck by moving my old php4 website to a new server of my company that only supports php5. In php4, objects were copied by value, and in php5 - by reference. Unfortunately, for me, the person who wrote this site made objects for others on the left and right, and now it causes all kinds of problems. Is there a setup or something that I can change to make php5 copy by value? If not, can I:

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

Thanks!

+3
source share
2 answers

Option B is the best choice. PHP5 redesigned object handling in a significant way, so if you have code that relies specifically on objects cloned using a PHP4 assignment, then, unfortunately, updating the code to PHP5, the cloning method is the best way to go in my opinion.

+2
source

I think the answer may need to be (B).

I'm not sure if you can create copy constructors that execute a clone in PHP (and I don’t have a machine at hand to check), but I would be interested if you can.

0
source

Source: https://habr.com/ru/post/1712747/


All Articles