Posted by Tom on 02/01/07 17:32
On Feb 1, 9:55 am, "Tamagafk" <tamag...@gmail.com> wrote:
> Hi there,
> I heard storing reference to THIS from inside object's constructor can
> cause problems:
>
> $myObjects = array();
> class MyClass{
> function MyClass(){
> global $myObjects;
> $myObjects[] = $this;
> }
>
> }
>
> Do you know anything about that? It looks like when constructor
> finishes all such references lead to COPY of the object.
If you actually want to reference instead of copy, you need to do:
$myObjects[] = &$this ;
You can also do this outside the constructor when defining your
instance, e.g.:
$myObjects[] = &$ref ;
$ref = new MyClass() ;
[Back to original message]
|