Skip to content

Commit

Permalink
📦 fread requires to pass only int<1, max> - early return empty st…
Browse files Browse the repository at this point in the history
…ring in case of `0` length
  • Loading branch information
andrew-demb committed Sep 1, 2024
1 parent eebe6b0 commit 10a13f1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,14 @@ public function isReadable(): bool
*/
public function read($length): string
{
if (0 === $length) {
return '';
}

if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
}

if (null === $this->getSize()) {
$read = fread($this->socket, $length);
if (false === $read) {
Expand Down

0 comments on commit 10a13f1

Please sign in to comment.