stream_get_contents
Function • Params and return types changed in PHP 8.0
Reads remainder of a stream into a string.
stream_get_contents Function synopsis
stream_get_contents(
$stream,
?int $length = null,
int $offset = -1
): string|false
Parameters
$stream
A stream resource (e.g. returned from fopen)
$length
OptionalType?intDefault valuenull
The maximum bytes to read. Defaults to null (read all the remaining
buffer).
$offset
OptionalTypeintDefault value-1
Seek to the specified offset before reading. If this number is negative, no seeking will occur and reading will start from the current position.
Return value
Typestring|false
Returns a string or false on failure.
Changes to the stream_get_contents Function
PHP 8.0
- Return type added:
string|false - Parameter name of parameter #1 changed:
$sourceto$stream - Parameter name of parameter #2 changed:
$maxlento$length - Parameter type added for parameter #2 (
$length):?int - Parameter default value added for position #2 (
$length):null - Parameter type added for parameter #3 (
$offset):int - Parameter default value added for position #3 (
$offset):-1
stream_get_contents(
- $source,
+ $stream,
- $maxlen,
+ ?int $length = null,
- $offset
+ int $offset = -1
- )
+ ): string|false stream_get_contents Function Availability
stream_get_contents Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |