Is it possible to unset (clean or un-instantiate) an object of a class by executing code of that particular class?
My scenario is one that, for some reason, I reach a point that the object has no meaning to exist anymore, so I want to make sure that is will not be used again by killing its reference in memory.
Here is a snippet example:
class Foo {
public $bar = "doh!";
function destroy() {
// ???
}
}
$o = new Foo();
echo $o->bar . '
';
$o->destroy();
echo $o->bar . '
'; // I expect an error here...
If I do a "unset" command outside the class code, it works, obviously:
$o = new Foo();
unset($o);
echo $o->bar . '
'; // PHP Notice: Undefined property: Foo::$bar in ...
But I tried to do it inside the "destroy" method, by calling "unset", or creating a custom "__destruct", but none worked.
Any ideas are very welcome.
Cheers,