Re: Re: unable to unset reference
| From: | Wolf | Date: | Tue, 19 Feb 2008 20:08:09 +0000 |
| Subject: | Re: Re: unable to unset reference | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-269657@lists.php.net to get a copy of this message | ||
---- Shawn McKenzie <nospam@mckenzies.net> wrote:
> Shawn McKenzie wrote:
> > 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.
> >
> > -Shawn
>
> Ignore everything that I have said or may say, I'm completely wrong :-(
>
Sure Shawn, you're just trying to increase your rankings for this week... ;)
Personally, objects are a b!tch to use, but I'm gradually working myself to the point of having
to learn and play nice with them.
Wolf