PHP Traversable interface

PHPServer Side ProgrammingProgramming

Introduction

Traversable is an abstract interface, hence it can not be directly implemented by any class. Generally, Iterator or IteratorAggregate interfaces, which extend Traversable, are used to check if implementing class is traversable using foreach construct in PHP.

Certain built-in classes that implement this interface can be used in foreach and need not implement iterator interfaces. Since Traversable is an abstract interface, it doesn't have any methods in it.

Syntax

Traversable {
   //
}

When implementing IteratorAggregate or Iterator interface which extends Traversable, they must be listed before its name in the implements clause.

raja
Published on 21-Sep-2020 12:04:55
Advertisements