public function __destruct() { foreach ($this->streams as $k => $v) { // if this is not a resource, it means the stream has already been // closed by client code if (is_resource($v)) { fclose($v); unset($this->streams[$k]); } } }