file = $file; } protected $file; function putContents(string $contents): void { if ($this->file === null) { parent::putContents($contents); } else { try { file_put_contents($this->file, $contents); } finally { $this->close(); } } } }