12-01-2007, 02:26 AM
|
#12 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 14
Thanks: 1
|
Quote:
Originally Posted by Salathe
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 :)
|
|
|
|