Re: unable to unset reference

From: Date: Tue, 19 Feb 2008 19:51:25 +0000
Subject: Re: unable to unset reference
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-269656@lists.php.net to get a copy of this message
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 :-(

« previous php.general (#269656) next »