View Single Post
Old 12-01-2007, 02:26 AM   #12 (permalink)
MartynMJ
The Wanderer
Newcomer 
 
Join Date: Nov 2007
Posts: 14
Thanks: 1
MartynMJ is on a distinguished road
Smile

Quote:
Originally Posted by Salathe View Post
There's a very simple solution.

Change: (in the class2 constructor)
PHP Code:
$this->class1 $class1
To:
PHP Code:
$this->class1 =& $class1
Why does this work? It's all about the way that PHP4 handles passing around references to objects. The &$class1 argument for the constructor ensured that the argument was brought in by reference, but when it was being assigned to the class1 property the assignment was by value -- a copy of the object was made and assigned to the property.

When we changed the data property, it was only changing it in the copy and not the original. Using =& the variable is assigned by reference as we intended. Hopefully you can see now why this behaviour was changed in PHP5 to assign by reference by default. :)


Works perfectly. Greatly appriciated :D.

Thanks very much :)
MartynMJ is offline  
Reply With Quote