public function getCleanupCallback() { $self = (object) array('ref' => $this); return function () use($self) { if (isset($self->ref)) { $self->ref->reset(); unset($self->ref); } }; }