File::offsetExists()

Checks if a line at a specified index exists in the file.

Table of Contents
  1. Description
  2. Example

Description

File::offsetExists(mixed $key): bool;

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 check the existence of a file chunk with array access syntax. This method checks if a line at a specified index exists in the file and will only work when checked using empty() or isset() language construct.

Example

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

test(empty($file[0])); // Returns `false`
test(isset($file[0])); // Returns `true`

File::offsetExists()

Checks if a line at a specified index exists in the file.

File::size()

Gets the file sizes in human readable string format.