Stream::getContents()

Source

public function getContents(): string
{
    if (!isset($this->stream)) {
        throw new \RuntimeException('Stream is detached');
    }
    $exception = null;
    \set_error_handler(static function ($type, $message) use (&$exception) {
        throw $exception = new \RuntimeException('Unable to read stream contents: ' . $message);
    });
    try {
        return \stream_get_contents($this->stream);
    } catch (\Throwable $e) {
        throw $e === $exception ? $e : new \RuntimeException('Unable to read stream contents: ' . $e->getMessage(), 0, $e);
    } finally {
        \restore_error_handler();
    }
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.