writer = $writer; $this->referenceCounter = $referenceCounter; $this->callbackId = $callbackId; $this->callbackDestructor = $callbackDestructor; $this->target = $target; } public function detach(): void { if ($this->callbackId === null) { return; } $this->writer->unregisterCallback($this->callbackId); $this->referenceCounter->release(); if ($this->callbackDestructor !== null) { unset($this->callbackDestructor->callbackIds[$this->callbackId]); } $this->callbackId = null; } public function __destruct() { if ($this->callbackDestructor !== null) { return; } if ($this->callbackId === null) { return; } $this->referenceCounter->acquire(true); $this->referenceCounter->release(); } }