File::getIterator()

The external iterator receiver.

Table of Contents
  1. Description
  2. Example

Description

File::getIterator(): Traversable;

This method is a requirement to be able to implement the IteratorAggregate interface and aims to make the object iterable directly. You won’t use this method directly, iteration control structures such as for, foreach and while will call this method automatically. For this class, this method will be passed to File::stream().

Example

$file = new File('.\path\to\file.txt');

// Using `for` loop
for ($i = 0, $j = count($file); $i < $j; ++$i) {
    echo $i . ': ' . $file[$i] . '<br>';
}

// Using `foreach` loop
foreach ($file as $k => $v) {
    echo $k . ': ' . $v . '<br>';
}

File::getIterator()

The external iterator receiver.

File::size()

Gets the file sizes in human readable string format.