Back to Stream class

Method gets

public mixed
gets
(mixed $length = 0)
Get a line from the stream source.
Parameters
  • int $length The number of bytes (optional) to read.
Returns
  • mixed
Since
  • 1.7.0
Class: Stream
Project: Joomla

Method gets - Source code

/**
 * Get a line from the stream source.
 *
 * @param   integer  $length  The number of bytes (optional) to read.
 *
 * @return  mixed
 *
 * @since   1.7.0
 */
public function gets($length = 0)
{
    if (!$this->fh) {
        $this->setError(Text::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN'));
        return false;
    }
    $retval = false;
    // Capture PHP errors
    $php_errormsg = 'Error Unknown';
    $track_errors = ini_get('track_errors');
    ini_set('track_errors', true);
    switch ($this->processingmethod) {
        case 'gz':
            $res = $length ? gzgets($this->fh, $length) : gzgets($this->fh);
            break;
        case 'bz':
        case 'f':
        default:
            $res = $length ? fgets($this->fh, $length) : fgets($this->fh);
            break;
    }
    if (!$res) {
        $this->setError($php_errormsg);
    } else {
        $retval = $res;
    }
    // Restore error tracking to what it was before
    ini_set('track_errors', $track_errors);
    // Return the result
    return $retval;
}