Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 400 and 403] [Versions 401 and 403]

(no description)

File Size: 265 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Stream:: (16 methods):
  __construct()
  __toString()
  close()
  detach()
  seek()
  isSeekable()
  getMetadata()
  getSize()
  tell()
  eof()
  rewind()
  write()
  isWritable()
  read()
  isReadable()
  getContents()


Class: Stream  - X-Ref

Describes a data stream.

Typically, an instance will wrap a PHP stream; this interface provides
a wrapper around the most common operations, including serialization of
the entire stream to a string.
__construct($stream)   X-Ref
No description

__toString()   X-Ref
Reads all data from the stream into a string, from the beginning to end.

This method MUST attempt to seek to the beginning of the stream before
reading data and read the stream until the end is reached.

Warning: This could attempt to load a large amount of data into memory.

This method MUST NOT raise an exception in order to conform with PHP's
string casting operations.

return: string

close()   X-Ref
Closes the stream and any underlying resources.

return: void

detach()   X-Ref
Separates any underlying resources from the stream.

After the stream has been detached, the stream is in an unusable state.

return: resource|null Underlying PHP stream, if any

seek($offset, $whence = SEEK_SET)   X-Ref
Seek to a position in the stream.

param: int $offset Stream offset
param: int $whence Specifies how the cursor position will be calculated

isSeekable()   X-Ref
Returns whether or not the stream is seekable.

return: bool

getMetadata($key = null)   X-Ref
Get stream metadata as an associative array or retrieve a specific key.

The keys returned are identical to the keys returned from PHP's
stream_get_meta_data() function.

param: string $key Specific metadata to retrieve.
return: array|mixed|null Returns an associative array if no key is

getSize()   X-Ref
Get the size of the stream if known.

return: int|null Returns the size in bytes if known, or null if unknown.

tell()   X-Ref
Returns the current position of the file read/write pointer

return: int Position of the file pointer

eof()   X-Ref
Returns true if the stream is at the end of the stream.

return: bool

rewind()   X-Ref
Seek to the beginning of the stream.

If the stream is not seekable, this method will raise an exception;
otherwise, it will perform a seek(0).


write($string)   X-Ref
Write data to the stream.

param: string $string The string that is to be written.
return: int Returns the number of bytes written to the stream.

isWritable()   X-Ref
Returns whether or not the stream is writable.

return: bool

read($length)   X-Ref
Read data from the stream.

param: int $length Read up to $length bytes from the object and return
return: string Returns the data read from the stream, or an empty string

isReadable()   X-Ref
Returns whether or not the stream is readable.

return: bool

getContents()   X-Ref
Returns the remaining contents in a string

return: string