fgets
Function • Params and return types changed in PHP 8.0
Gets line from file pointer.
fgets Function synopsis
fgets($stream, ?int $length = null): string|false
Parameters
$stream
$length
OptionalType?intDefault valuenull
Reading ends when $length - 1 bytes have been
read, or a newline (which is included in the return value), or an EOF
(whichever comes first). If no length is specified, it will keep
reading from the stream until it reaches the end of the line.
Return value
Typestring|false
Returns a string of up to $length - 1 bytes read from
the file pointed to by $stream. If there is no more data
to read in the file pointer, then false is returned.
If an error occurs, false is returned.
Changes to the fgets Function
PHP 8.0
- Return type added:
string|false - Parameter name of parameter #1 changed:
$fpto$stream - Parameter type added for parameter #2 (
$length):?int - Parameter default value added for position #2 (
$length):null
- fgets($fp, $length)
+ fgets($stream, ?int $length = null): string|false fgets Function Availability
fgets 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 |