Re: unsetting an instance from within its class
| From: | Michael Virnstein | Date: | Thu, 11 Apr 2002 08:38:15 +0000 |
| Subject: | Re: unsetting an instance from within its class | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-92527@lists.php.net to get a copy of this message | ||
you can use unset($this), but it'll only work if there are no
other variables referencing to this object. unset only unsets the reference
to value, not the value itself. PHP will unset the value totally, if there
are no references to it anymore.
so using $this = null; , is perhaps the better solution.
example for unset not unsetting the value but the reference:
<?php
class test {
var $test1 = "";
function test($str) {
$this->test1 = $str;
}
function kill() {
unset($this);
}
}
$new =& new test("hallo");
$test = &$new;
$new->kill();
echo $test->test1;
?>
this will output hallo, although you called unset($this).
"Erik Price" <pricee@hhbrown.com> schrieb im Newsbeitrag
news:A0632096-4C9C-11D6-BC9F-0050E4857868@hhbrown.com...
> Is there a way to unset or destroy an object instance from a method
> within its class? I'm trying to write a method that destroys its
> instance but I'm not sure how to refer to the object itself from within
> the class.
>
>
> Erik
>
>
>
>
>
> ----
>
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown
> pricee@hhbrown.com
>