I am writing a Proxy class in PHP.
To do so, I am using magic method to catch calls/get/set… to the proxied instance, and forward them to that instance.
However, I am unsure what to do in this situation:
class Proxy {
// Proxied object
private $instance;
// ...
function __destruct() {
// unset($this->instance); ?
// $this->instance->__destruct(); ?
// nothing ?
}
}
Should I (can I) call the destructor explicitly? Or should I just unset the object, knowing it won’t really destroy it for sure (at least, immediately)?
Or should I just do nothing and wait for the garbage collector to destroy the instance?
Don’t do anything. It’ll be taken care of by the garbage collector, probably at around the same time as the proxy.