|
Posted by Lόpher Cypher on 12/29/05 16:07
Hi,
Suppose I instantiate an object $a and store it in a global array. Now,
if I change a property of $a, the property in $a will have the new
value, but the property in the global array will have the old one. Does
anyone know workarounds?
global $global;
$global = array();
class A {
var $i;
function A() {
$this->i = 0;
}
function chg() {
$this->i += 2;
}
}
$a = new A();
$global[0] = $a;
$b = new A();
$global[1] = $b;
// here $global[0]->i == $global[1]->i == $a->i == $b->i == 0
$a->chg();
// here $global[0]->i == 0, $a->i == 2
Is there a way to store an object by reference so that whenever its
properties change, the global array item would still be referring the
actual object and not a copy of it I assume it made on the assigment?
Thanks,
luph
Navigation:
[Reply to this message]
|