public function gets(?int $maxLength = null) : string
    {
        if ($this->closed) {
            throw new IoException('The stream is closed.');
        }

        try {
            $data = ErrorCatcher::run(function() use ($maxLength) {
                if ($maxLength === null) {
                    return fgets($this->handle);
                } else {
                    return fgets($this->handle, $maxLength + 1);
                }
            });
        } catch (\ErrorException $e) {
            throw new IoException($e->getMessage(), 0, $e);
        }

        if ($data === false) {
            return '';
        }

        return $data;
    }
public function gets(?int $maxLength = null) : string
    {
        if ($this->closed) {
            throw new IoException('The stream is closed.');
        }

        try {
            $data = ErrorCatcher::run(function() use ($maxLength) {
                if ($maxLength === null) {
                    return fgets($this->handle);
                } else {
                    return fgets($this->handle, $maxLength + 1);
                }
            });
        } catch (\ErrorException $e) {
            throw new IoException($e->getMessage(), 0, $e);
        }

        if ($data === false) {
            return '';
        }

        return $data;
    }
public function gets ( ? int $ maxLength = null ) : string { if ( $ this -> closed ) { throw new IoException ( 'The stream is closed.' ) ; } try { $ data = ErrorCatcher :: run ( function ( ) use ( $ maxLength ) { if ( $ maxLength === null ) { return fgets ( $ this -> handle ) ; } else { return fgets ( $ this -> handle , $ maxLength + 1 ) ; } } ) ; } catch ( \ ErrorException $ e ) { throw new IoException ( $ e -> getMessage ( ) , 0 , $ e ) ; } if ( $ data === false ) { return '' ; } return $ data ; }
Reads a line from the stream.

@param int|null $maxLength The max length in bytes to read. If no max length is specified, it will keep reading
from the stream until it reaches the end of the line or EOF.

@return string The data, or an empty string if there is no more data to read.

@throws IoException If an error occurs.
Reads a line from the stream .