File::offsetGet()

Gets a line at a specified index in the file.

Table of Contents
  1. Description
  2. Example

Description

File::offsetGet(mixed $key): ?string;

This method is a requirement to be able to implement the ArrayAccess interface and aims to make the object data accessible using array access syntax. You won’t use this method directly, it will be executed automatically when you try to get a file chunk with array access syntax. This method gets a file chunk using its index. If the index does not exist in the file, this method returns null.

Example

// Assume that the file contains `'aaa\nbbb\nccc'`
$file = new File('.\path\to\file.txt');

test($file[0]); // Returns `'aaa\n'`
test($file[5]); // Returns `null`

File::offsetGet()

Gets a line at a specified index in the file.

File::size()

Gets the file sizes in human readable string format.