|
Posted by Oli Filth on 12/29/05 16:30
Lüpher Cypher said the following on 29/12/2005 14: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?
>
<...SNIP CODE...>
>
> 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?
I'm assuming you must be using PHP 4, because this works as you want it
to in PHP 5.
In PHP 4, objects are copied by value; in PHP 5, objects are copied by
reference.
To copy by reference in PHP 4, use &, i.e.:
$global[0] =& $a;
(P.S. This is nothing to do with global variables...)
--
Oli
Navigation:
[Reply to this message]
|