Re: Re: unable to unset reference
| From: | Zoltán Németh | Date: | Wed, 20 Feb 2008 08:08:48 +0000 |
| Subject: | Re: Re: unable to unset reference | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269700@lists.php.net to get a copy of this message | ||
2008. 02. 19, kedd keltezéssel 13.39-kor Shawn McKenzie ezt írta:
> Sylvain Rabot wrote:
> > Hello,
> >
> > First of all I would like to know if one day we will be able to unset
> > $this into a class in order to destroy the object. It could really be
> > useful to prevent big memory usage.
> >
> > As it can't be done I tried to unset an object by unsetting a reference
> > of this object but it has no effect on the object but only on the
> > reference.
> >
> > Should unset destroy the reference itself and the object ???
> >
> > if you don't think so can you think of something different to destroy
> > both of them like I don't know, destroy($obejctsreference)
> >
> > Regards.
> >
> > Reproduce code:
> > ---------------
> > <?
> >
> > $x = new stdClass();
> > $x->a = 'ayayaye';
> >
> > $b[0] =& $x;
> >
> > unset($b[0]);
> >
> > var_dump($x);
> >
> > ?>
> >
> > Expected result:
> > ----------------
> > NULL
> >
> > Actual result:
> > --------------
> > object(stdClass)#1 (1) {
> > ["a"]=>
> > string(7) "ayayaye"
> > }
>
> So if you unset a reference you are dereferencing it. If you want to
> unset both, then unset the object, in this case $x.
I think he should unset all references to the object, $x and $b[0] as
well.
greets
Zoltán Németh
>
> -Shawn
>