PHP5 vs PHP4 Object Cloning

I read alot about how PHP5 makes a reference to an object, but PHP4 clones an object when the following is done:

$object2 = $object1

I understand the difference between the two but the PHP5 way is always said to be better. But why? If you did the same with a variable, php would make a copy of the variable. So from the standards of PHP in general, PHP4’s method of object cloning was more intuitive. Is there any reason why PHP5’s method is BETTER, and not just a change to be in line with other OO languages?

Object being reference variable is a key feature in modern OO languages. It not only speeds up the program, but also makes it possible for the state of an object to be managed in multiple classes/programs without having to make copies or explicitly declare references. A good example is dependency injection, when an object is passed around in multiple objects that use it. Without assigning by reference, you make copies each time the object is assigned as a property of another object, it will be considerably slower(lets say a database connection object). On the other hand, for objects such as domain models/entities, it’s important to realize that these objects have identities and that by copying such identity objects you create different objects. This is not a good OOP design, as your objects now have messed-up identities. The beauty of assigning objects by reference is that multiple properties/variables point to the same object in memory, its much easier and clear to use an object this way.

I’ll have to take your word for it. I still need to do more reading I think to see the benefits in more advanced structure since I am still new to OOP. But the benefit is clear with database objects as you mentioned. Thank you.