Skip to content

Commit

Permalink
Ensure the output stream is always closed when it goes out of scope
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Dec 2, 2023
1 parent e1ac371 commit 968b8de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Web change log

## 3.11.0 / 2023-12-02

* Ensured the output stream is always closed when it goes out of scope
(@thekid)
* Removed superfluous layer of output buffering in development webserver
(@thekid)
* Merged PR #105: Implement `WriteChunks::flush()` to use for explicitely
Expand Down
5 changes: 5 additions & 0 deletions src/main/php/web/io/Output.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public function close() {
$this->finish();
$this->closed= true;
}

/** Ensures `close()` is called */
public function __destruct() {
$this->close();
}
}
15 changes: 15 additions & 0 deletions src/test/php/web/unittest/io/OutputTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@ public function finish() { $this->finished++; }

Assert::equals(1, $out->finished);
}

#[Test]
public function destructor_calls_finish() {
$finished= 0;
$out= new class($finished) extends Output {
private $finished;
public function __construct(&$finished) { $this->finished= &$finished; }
public function begin($status, $message, $headers) { }
public function write($bytes) { }
public function finish() { $this->finished++; }
};
$out= null;

Assert::equals(1, $finished);
}
}

0 comments on commit 968b8de

Please sign in to comment.