Skip to content

Commit

Permalink
dont throw errors on double close in stream wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Mar 12, 2021
1 parent 22ef9fc commit 93bce47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public function stream_eof() {
}

public function stream_close() {
return fclose($this->source);
if (is_resource($this->source)) {
return fclose($this->source);
}
}

public function dir_readdir() {
Expand Down
11 changes: 11 additions & 0 deletions tests/WrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,15 @@ public function testRewindDir() {
rewinddir($wrapped);
$this->assertSame($content[0], readdir($wrapped));
}

public function testDoubleClose() {
$source = fopen('php://temp', 'r+');
rewind($source);

$wrapped = $this->wrapSource($source);

fclose($source);
fclose($wrapped);
$this->assertFalse(is_resource($source));
}
}

0 comments on commit 93bce47

Please sign in to comment.